QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#247976 | #7678. The Game | trigriffin# | WA | 11ms | 3632kb | C++14 | 2.1kb | 2023-11-11 16:50:28 | 2023-11-11 16:50:28 |
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);
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;++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
{
if(n==m)
{
flag=0;
for(int i=0;i<n;++i)
if(a[i]!=b[i])
{
flag=1;
break;
}
if(flag)
cout<<-1<<"\n";
else cout<<0<<"\n";
}
else
{
cout<<n-m<<"\n";
for(int i=0;i<n-m;++i)
cout<<ans[i]<<" ";
cout<<"\n";
}
// cout<<"\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: -100
Wrong Answer
time: 11ms
memory: 3632kb
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 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 2 1 2 1...
result:
wrong answer Wrong answer, the final sequence does not equal to B (test case 3)