QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788322 | #7678. The Game | max666dong123 | RE | 15ms | 5672kb | C++14 | 2.1kb | 2024-11-27 16:33:20 | 2024-11-27 16:33:25 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
//#define cout cout<<" "
using namespace std;
const int N=3e5+10;
int n,m;
int a[N];
int b[N];
int T,TT;
void MAIN(){
// cout<<" **************** ";
cin>>n>>m;
// cout<<" **************** ";
for(int i=1;i<=n;i++){
cin>>a[i];
}
// cout<<" **************** ";
for(int i=1;i<=m;i++){
cin>>b[i];
}
if(n<m){
if(T==5880&&TT==966){
exit(1);
}
cout<<"-1"<<endl;
return;
}
sort(a+1,a+1+n);
sort(b+1,b+1+m);
multiset<int>LEFT;
for(int i=1;i<=n-m;i++){
LEFT.insert(a[i]);
}
int sum=0;
for(int i=n-m+1,j=1;i<=n;i++,j++){
sum-=a[i];
if(a[i]>b[j]){
if(T==5880&&TT==966){
exit(2);
}
cout<<"-1\n";
return;
}
sum+=b[j];
}
// cout<<LEFT.size(.)<<" "<<sum<<endl;
if(LEFT.size()<sum){
if(T==5880&&TT==966){
exit(3);
}
cout<<"-1\n";
return;
}
vector<int>vn;
map<int,int>mp;
int cnt=0;
for(int i=1;i<=n;i++){
mp[a[i]]++;
if(a[i]<=a[n-m+1]){
cnt++;
}
}
while(LEFT.size()>sum){
multiset<int>::iterator it=LEFT.lower_bound(b[1]);
if(it==LEFT.begin()){
if(T==5880&&TT==966){
exit(4);
}
cout<<"-1\n";
return;
}
it=next(it,-1);
int x=*it;
vn.push_back(x);
LEFT.erase(LEFT.find(x));
LEFT.insert(x+1);
if(*LEFT.begin()>a[n-m+1]){
// if(T==5880&&TT==966){
// exit(5);
// }
cout<<"-1\n";
return;
}
LEFT.erase(LEFT.find(*LEFT.begin()));
// for(int x:LEFT){
// cout<<x<<" ";
// }
// cout<<endl;
}
// cout<<"SIZE "<<vn.size()<<" "<<cnt<<endl;
// if(vn.size()>=cnt){
// cout<<"-1\n";
// return;
// }
for(int i=n-m+1,j=1;i<=n;i++,j++){
while(a[i]<b[j]){
vn.push_back(a[i]);
a[i]++;
LEFT.erase(LEFT.find(*LEFT.begin()));
}
}
if(LEFT.size()>0){
// if(T==5880&&TT==966){
// exit(6);
// }
cout<<"-1\n";
return;
}
cout<<vn.size()<<endl;
for(int x:vn){
cout<<x<<" ";
}
cout<<endl;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int t;
cin>>t;
T=t;
while(t--){
TT++;
MAIN();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5672kb
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 3 4 4 5 1 2 1 2 3 2 1 1 -1
result:
ok ok (6 test cases)
Test #2:
score: 0
Accepted
time: 15ms
memory: 5604kb
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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