QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250188#7678. The GameMasterGwxWA 3ms3404kbC++141.8kb2023-11-12 22:36:282023-11-12 22:36:29

Judging History

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

  • [2023-11-12 22:36:29]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3404kb
  • [2023-11-12 22:36:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=1e18+3;
#define DEBUG 
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(x)
#else
#define debug(...) {}
#endif
//debug(n,m);debug("a,b");
//double max:0x7f,0x43 min:0xfe 0x c2  int:0x3f 
//运算符 priority  后缀 前缀 */+- 位移 比较 &^| && || 赋值

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(m),ans,res;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int k=0,p1=n-1,p2=m-1;
    while(k<n-m && p2>=0){
        if(a[p1]>b[p2] || k>p1) {
            cout<<-1<<'\n';
            return;
        }
        for(int i=a[p1];i<b[p2];i++) ans.push_back(i);
        k+=b[p2]-a[p1];
        a[p1]=b[p2];
        p2--,p1--;
    }
    if(k>n-m){
        cout<<"-1\n";
        return;
    }
    //debug(p1,p2);
    priority_queue<int,vector<int>,greater<int>> q;
    //debug(k);
    p1=0;
    while(k<n-m){
        q.push(a[p1]),k++,p1++;
    }
    //debug(q.size());
    while(!q.empty()){
        int x=q.top();
        q.pop();
        res.push_back(x);
        //debug(x);
        if(q.empty()){
            if(x==b[0]){
                cout<<"-1\n";
                return;
            }
        }
        q.push(x+1);
        q.pop();
    }
    cout<<ans.size()+res.size()<<'\n';
    for(auto i:res) cout<<i<<" ";
    for(auto i:ans) cout<<i<<" ";
    cout<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #if 1 
        int T; cin>>T; while(T--) solve();
    #else 
        solve();
    #endif 
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 2 1 2 3 
2
1 1 
-1

result:

ok ok (6 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3404kb

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

output:

-1
1
1 
-1
-1
-1
-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 
-1
-1
-1
1
1 
1
2 
-1
-1
-1
1
2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1 
1
2 
-1
-1
-1
1
2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 ...

result:

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