QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#250467 | #7678. The Game | ucup-team2279 | WA | 0ms | 3428kb | C++14 | 1.0kb | 2023-11-13 10:16:53 | 2023-11-13 10:16:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,m,cnt=0;
cin>>n>>m;
vector<int> ans,a(n),b(m);
for(int&x:a) cin>>x;
for(int&x:b) cin>>x;
sort(a.rbegin(),a.rend());
sort(b.rbegin(),b.rend());
for(int i=0;i<m;i++){
if(a[i]>b[i]){
cout<<"-1\n";
return;
}
cnt+=b[i]-a[i];
if(n-cnt<m){
cout<<"-1\n";
return;
}
}
multiset<int> s(begin(a),begin(a)+m),t(begin(a)+m,end(a));
for(;n-cnt>m;n--){
if(t.empty()){
cout<<"-1\n";
return;
}
int x=*t.begin();
ans.push_back(x++);
t.erase(t.begin());
if(x>*s.begin()) cnt--,s.erase(s.begin()),s.insert(x),t.insert(x-1);
else t.insert(x);
t.erase(t.begin());
}
int p=0;
for(int x:s) a[p++]=x;
reverse(begin(a),begin(a)+m);
for(int i=0;i<m;i++){
if(a[i]>b[i]){
cout<<"-1\n";
return;
}
while(a[i]<b[i]) ans.push_back(a[i]++);
}
cout<<n-m<<"\n";
for(int x:ans) cout<<x<<" ";
cout<<"\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3428kb
input:
6 5 3 1 2 2 3 3 2 3 4 4 2 1 2 2 4 2 4 5 2 2 3 3 4 4 5 5 6 1 1 1 1 1 1 1 4 4 2 1 1 1 2 2 2 4 1 1 1 1 1 2
output:
1 1 3 -1 2 2 4 4 2 1 1 1 2 3 0 1 1 -1
result:
wrong answer Wrong answer, number of operation is not correct (test case 1)