QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788096 | #7678. The Game | max666dong123 | WA | 11ms | 5664kb | C++14 | 1.8kb | 2024-11-27 15:55:44 | 2024-11-27 15:55:44 |
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];
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){
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]){
cout<<"-1\n";
return;
}
sum+=b[j];
}
// cout<<LEFT.size(.)<<" "<<sum<<endl;
if(LEFT.size()<sum){
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()){
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]){
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()));
}
}
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;
while(t--){
MAIN();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
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: 11ms
memory: 5532kb
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 2 -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 ...
result:
ok ok (7056 test cases)
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 5660kb
input:
5880 4 2 1 1 1 1 1 1 4 2 1 1 1 1 1 2 4 2 1 1 1 1 1 3 4 2 1 1 1 1 1 4 4 2 1 1 1 1 1 5 4 2 1 1 1 1 1 6 4 2 1 1 1 1 1 7 4 2 1 1 1 1 2 2 4 2 1 1 1 1 2 3 4 2 1 1 1 1 2 4 4 2 1 1 1 1 2 5 4 2 1 1 1 1 2 6 4 2 1 1 1 1 2 7 4 2 1 1 1 1 3 3 4 2 1 1 1 1 3 4 4 2 1 1 1 1 3 5 4 2 1 1 1 1 3 6 4 2 1 1 1 1 3 7 4 2 1 1...
output:
-1 -1 2 1 2 -1 -1 -1 -1 2 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 2 3 -1 -1 -1 2 1 1 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 3 4 -1 -1 -1 2 1 1 2 1 3 -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:
wrong answer Jury has answer but participant has not (test case 966)