QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630343#8549. The GameSatsukiWA 0ms3832kbC++141.6kb2024-10-11 18:02:482024-10-11 18:02:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 18:02:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-10-11 18:02:48]
  • 提交

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'