QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#250651 | #7678. The Game | MasterGwx | WA | 1ms | 3428kb | C++14 | 2.3kb | 2023-11-13 15:04:27 | 2023-11-13 15:04:27 |
Judging History
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 后缀 前缀 */+- 位移 比较 &^| && || 赋值
int T,t;
void solve()
{
int n,m;
int t;
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];
p2--,p1--;
}
if(k>n-m || p2>=0){
cout<<"-1\n";
return;
}
priority_queue<int,vector<int>,greater<int>> q;
for(int i=0;i<n;i++) q.push(a[i]);
//debug(q.size());
for(int i=1;i<=n-m-k;i++){
int x=q.top();
q.pop();
res.push_back(x);
//debug(x);
q.push(x+1);
q.pop();
}
a.clear();
while(!q.empty()){
a.push_back(q.top());
q.pop();
}
//for(auto i:a) cout<<i<<' '; cout<<endl;
k=n-m-k,p1=a.size()-1,p2=m-1;
while(k<=n-m && p2>=0){
if(a[p1]>b[p2] ) {
cout<<-1<<'\n';
return;
}
for(int i=a[p1];i<b[p2];i++) res.push_back(i);
k+=b[p2]-a[p1];
p2--,p1--;
}
p1=0;
while(k<n-m){
if(a[p1]>=b[0]) {
cout<<"-1\n";
return;
}
res.push_back(a[p1]);
p1++; k++;
}
if(k!=n-m){
cout<<"-1\n";
return;
}
cout<<res.size()<<'\n';
for(auto i:res) cout<<i<<" ";
cout<<'\n';
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#if 1
cin>>T;
for(int i=1;i<=T;i++) {
t++;
solve();
}
#else
solve();
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
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:
2 1 3 -1 3 2 4 4 5 1 1 2 3 1 2 1 1 -1
result:
wrong answer Wrong answer, erase a number that does not exist (test case 4)