QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630343 | #8549. The Game | Satsuki | WA | 0ms | 3832kb | C++14 | 1.6kb | 2024-10-11 18:02:48 | 2024-10-11 18:02:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int>mp;
int n,m;
vector<int>ai,bi,res;
void solve(){
scanf("%lld%lld",&n,&m);
ai.clear();bi.clear();res.clear();
ai.push_back(0);
bi.push_back(0);
for(int i=1;i<=n;i++){
int a;scanf("%lld",&a);
ai.push_back(a);
}
sort(ai.begin(),ai.end());
for(int i=1;i<=m;i++){
int b;scanf("%lld",&b);
bi.push_back(b);
}
for(int i=1;i<=n-m;i++)
bi.push_back(0);
sort(bi.begin(),bi.end());
int ans=0;
for(int i=n-m+1;i<=n;i++)
if(ai[i]>bi[i]){printf("-1\n");return ;}
else ans+=bi[i]-ai[i];
if(ans>n-m){printf("-1\n");return ;}
for(int i=n-m;i>=1;i--)
bi[i]=1e9;
for(int i=1;i<=n;i++)
mp[ai[i]]=i;
// for(int i=1;i<=n;i++)printf("(%lld)",ai[i]);printf("\n");
// for(int i=1;i<=n;i++)printf("(%lld)",bi[i]);printf("\n");
// for(int i=1;i<=n;i++)printf("(%lld)",mp[ai[i]]);printf("\n");
int cnt=n-m-ans;
for(int i=1;i<=n-m;i++){
if(cnt){
int j=mp[ai[i]];
if(bi[i]<=ai[i])continue;
res.push_back(ai[i]);
mp[ai[i]]=j-1;ai[j]++;
mp[ai[j]]=max(mp[ai[j]],j);
if(j<=n-m)cnt--;
}
}
if(cnt){printf("-1\n");return ;}
for(int i=n-m+1;i<=n;i++){
for(int j=ai[i];j<bi[i];j++)
res.push_back(j);
}
printf("%lld\n",n-m);
sort(res.begin(),res.end());
for(int i:res)printf("%lld ",i);
printf("\n");
}
signed main(){
int t;scanf("%lld",&t);
for(int i=1;i<=t;i++)
solve();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
3 3 1 1 4 5 1 4 2 1 2 3 4 4 1 2 2 3 2 1 1 4
output:
-1 -1 -1
result:
wrong answer 1st words differ - expected: 'Qingyu', found: '-1'