QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#247900 | #7678. The Game | trigriffin# | WA | 1ms | 3404kb | C++14 | 1.9kb | 2023-11-11 16:27:39 | 2023-11-11 16:27:41 |
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;
if(l==0)
{
if(a[0]!=a[1])
return 0;
else l=1;
}
for(int i=l;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);
for(int i=0;i<m;++i)
{
s0+=b[i];
s+=a[i+n-m];
}
if(s>s0||n-m<s-s0)
{
cout<<-1<<"\n";
continue;
}
// cout<<s0<<' '<<s<<endl;
bool flag=0;
int i=0,j=n-1;
for(int cnt=0;cnt<n-m-1;++cnt)
{
// cout<<i<<endl;
// cout<<cnt<<' '<<s<<' '<<s0<<endl;
if(s0<s)
{
flag=1;
break;
}
if(s0-s>1)
{
// 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: 0
Wrong Answer
time: 1ms
memory: 3404kb
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 4 2 4 5 1 2 1 1 3 2 1 1 -1
result:
wrong answer Wrong answer, erase a number that does not exist (test case 3)