QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#699036#7678. The GamejiangzhihuiWA 6ms3820kbC++232.7kb2024-11-01 23:55:522024-11-01 23:55:58

Judging History

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

  • [2024-11-01 23:55:58]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3820kb
  • [2024-11-01 23:55:52]
  • 提交

answer

#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include<bits/Bingbong.h>
#endif
using namespace std;
#define i64 long long
#define pi acos(-1)
void solve(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n+1),b(m+1);
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=1;i<=m;i++) cin>>b[i];

  sort(a.begin()+1,a.begin()+n+1);
  sort(b.begin()+1,b.begin()+m+1);
  int l1=n,l2=m;
  i64 cz_val=0;
  while(l1>0&&l2>0){
    if(a[l1]>b[l2]){
      cout<<"-1\n";
      return ;
    }else{
      cz_val+=b[l2]-a[l1];
    }
    l1--;
    l2--;
  }
  vector<int>ans;
  if(cz_val<n-m){
    //case 1
    priority_queue<int,vector<int>,greater<int>>q;
    for(int i=1;i<=n;i++){
      q.push(a[i]);
    }
    //debug(q.size(),cz_val);
    while(q.size()-cz_val>m){
      auto t=q.top();
      q.pop();
      ans.push_back(t);
      t++;
      q.push(t);
      q.pop();
    }
    //debug(q.top(),q.size());
    if(q.top()>b[1]){
      cout<<"-1\n";
      return ;
    } 
    //小的处理好了,只需要把差值对应的加上去
    //把队列中元素搞成容器
    vector<int>ta(n+1);
    int k=0;
    while(!q.empty()){
      ta[++k]=q.top();
      q.pop();
    }
   // debug(k);

    if(k-cz_val!=m){
      cout<<"-1\n";
      return ;
    }
    int L1=k,L2=m;
    int newcz=0;
    while(L1>0&&L2>0){
      if(ta[L1]>b[L2]){
        cout<<"-1\n";
        return ;
      }else{
         newcz+=b[L2]-ta[L1];
      }
      L1--;
      L2--;
    }
    //debug(k,newcz);
    // 存在唯一情况,就是 那个小于的可以自己删掉
    if(k-newcz>m){
      //debug(k,newcz);
      // 看下最小的能不能删掉
      int tz=k-newcz-m;
      for(int i=1;i<=tz;i++){
        if((ta[i]+1>ta[i+1])&&newcz==0){
          cout<<"-1\n";
          return ;
        }else{
          ans.push_back(ta[i]);
        }
      }
    }
    L1=k;
    L2=m;
    while(1){
      while(ta[L1]<b[L2]){
        ans.push_back(ta[L1]);
        ta[L1]++;
      }
      L1--;
      L2--;
      if(L2==0){
        break;
      }
    }

  }else if(cz_val==n-m){
    int l1=n,l2=m;
    while(1){
      while(a[l1]<b[l2]){
        ans.push_back(a[l1]);
        a[l1]++;
      }
      l1--;
      l2--;
      if(l2==0){
        break;
      }
    }
  }else{
    cout<<"-1\n";
    return ;
  }

  //
  cout<<ans.size()<<"\n";
  for(auto t:ans){
    cout<<t<<" ";
  }
  cout<<"\n";

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--) {
      solve();
    }
    return 0;
}
/*
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

*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

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:

2
1 3 
-1
3
2 4 4 
5
1 1 1 2 3 
2
1 1 
-1

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 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
2
3 1 
-1
-1
-1
2
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (5880 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

2640
4 1
1 1 1 1
1
4 1
1 1 1 1
2
4 1
1 1 1 1
3
4 1
1 1 1 1
4
4 1
1 1 1 1
5
4 1
1 1 1 1
6
4 1
1 1 1 1
7
4 1
1 1 1 1
8
4 1
1 1 1 2
1
4 1
1 1 1 2
2
4 1
1 1 1 2
3
4 1
1 1 1 2
4
4 1
1 1 1 2
5
4 1
1 1 1 2
6
4 1
1 1 1 2
7
4 1
1 1 1 2
8
4 1
1 1 1 3
1
4 1
1 1 1 3
2
4 1
1 1 1 3
3
4 1
1 1 1 3
4
4 1
1 1 1 3
5
4...

output:

-1
-1
3
1 1 2 
3
1 2 3 
-1
-1
-1
-1
-1
-1
3
1 1 2 
3
1 2 3 
3
2 3 4 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 3 
3
1 3 4 
3
3 4 5 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 4 
3
1 4 5 
3
4 5 6 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 5 
3
1 5 6 
3
5 6 7 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 6 
3
1 6 7 
-1
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 7 
...

result:

ok ok (2640 test cases)

Test #5:

score: 0
Accepted
time: 6ms
memory: 3820kb

input:

14112
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
1 1 2
5 3
1 1 1 1 1
1 1 3
5 3
1 1 1 1 1
1 1 4
5 3
1 1 1 1 1
1 1 5
5 3
1 1 1 1 1
1 1 6
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 2 3
5 3
1 1 1 1 1
1 2 4
5 3
1 1 1 1 1
1 2 5
5 3
1 1 1 1 1
1 2 6
5 3
1 1 1 1 1
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...

result:

wrong answer Wrong answer, the final sequence does not equal to B (test case 3)