QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#248305 | #7678. The Game | frozen_wjl | WA | 11ms | 3592kb | C++14 | 1.9kb | 2023-11-11 18:17:06 | 2023-11-11 18:17:06 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[300005],b[300005];
int n;
vector<int>ans;
int get(int cnt,int l)
{
// cout<<cnt<<' '<<l<<endl;
if(cnt<l)
return l;
else if(cnt>l)
l=cnt;
for(int i=l+1;i<n;++i)
{
if(a[i]!=a[i-1])
return i-1;
}
return n-1;
}
int main()
{
int t,m,s0,s;
cin>>t;
while(t--)
{
ans.clear();
cin>>n>>m;
s0=s=0;
for(int i=0;i<n;++i)
cin>>a[i];
sort(a,a+n);
for(int i=0;i<m;++i)
{
cin>>b[i];
}
sort(b,b+m);
bool flag=0;
for(int i=0;i<m;++i)
{
s0+=b[i];
s+=a[i+n-m];
if(a[i+n-m]>b[i])
flag=1;
}
if(flag||s>s0||n-m<s0-s)
{
cout<<-1<<"\n";
continue;
}
// cout<<s0<<' '<<s<<endl;
flag=0;
int i=0,j=n-1;
for(int cnt=0;cnt<n-m;++cnt)
{
// cout<<i<<endl;
// cout<<cnt<<' '<<s<<' '<<s0<<endl;
if(s0<s)
{
flag=1;
break;
}
if(s0-s>=n-m-cnt)
{
// cout<<i<<endl;
for(;j>=cnt;--j)
{
if(a[j]!=b[j+m-n])
{
ans.push_back(a[j]);
++a[j];
++s;
break;
}
if(j==cnt)
{
flag=1;
break;
}
}
}
else
{
i=get(cnt,i);
ans.push_back(a[i]);
++a[i];
// cout<<i<<endl;
if(i>=n-m)
++s;
--i;
// cout<<cnt<<' '<<s<<' '<<s0<<endl;
}
}
/*
if(s0-s==1)
{
for(;j>=n-m-1;--j)
{
if(a[j]!=b[j+m-n])
{
ans.push_back(a[j]);
++a[j];
++s;
break;
}
}
}
else if(s0==s)
{
// cout<<a[n-m]<<' '<<a[n-m-1]<<endl;
if(a[n-m]>a[n-m-1])
ans.push_back(a[n-m-1]);
else flag=1;
}
*/
// for(int i=0;i<ans.size();++i)
// cout<<ans[i]<<' ';
if(s!=s0)
flag=1;
if(flag)
cout<<-1<<"\n";
else
{
{
cout<<n-m<<"\n";
for(int i=0;i<n-m;++i)
cout<<ans[i]<<" ";
cout<<"\n";
}
// cout<<"\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
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: 11ms
memory: 3592kb
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: 0ms
memory: 3588kb
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 2 1 1 2 2 3 -1 -1 -1 2 1 1 2 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 1 1 2 3 4 -1 -1 -1 2 1 1 2 3 1 -1 -1 -1 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer Wrong answer, the final sequence does not equal to B (test case 31)