QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368063 | #5260. The Game | liswt | WA | 1ms | 3556kb | C++20 | 1.6kb | 2024-03-26 19:31:42 | 2024-03-26 19:31:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int T;
int n,m;
int a[N];
int b[N];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
}
vector<int>ans;
sort(a+1,a+n+1,cmp);
sort(b+1,b+m+1,cmp);
int add=0,del=0;
multiset<int>u,v;
for(int i=1;i<=m;i++)
{
add+=b[i]-a[i];
u.insert(a[i]);
}
for(int i=m+1;i<=n;i++)
{
del++;
v.insert(a[i]);
}
// int det=del-add;
while(del>0&&del-add>0)
{
// cout<<del<<"----"<<add<<endl;
// for(auto op:u)cout<<op<<" ";cout<<endl;
// for(auto op:v)cout<<op<<" ";cout<<endl;
auto x=v.begin();
auto y=u.begin();
v.erase(x);
ans.push_back(*x);
if(*x+1>*y)
{
u.erase(y);
v.insert(*y);
u.insert(*x+1);
add--;
}
else
{
v.insert(*x+1);
}
v.erase(v.begin());
del--;
}
// cout<<"add:"<<add<<" "<<"del:"<<del<<endl;
// cout<<"ans is~~~~~~~~~~~~~~~~~~~"<<endl;
if(add>del)
{
cout<<"-1"<<endl;
continue;
}
int ok=1;
for(int i=m;i>=1;i--)
{
auto x=u.begin();
a[i]=*x;
u.erase(x);
}
for(int i=1;i<=m;i++)
{
if(a[i]>b[i])
{
ok=0;
break;
}
while(a[i]<b[i])
{
ans.push_back(a[i]);
a[i]++;
}
}
if(!ok)
{
cout<<"-1"<<endl;
continue;
}
cout<<ans.size()<<endl;
for(auto x:ans)
{
cout<<x<<" ";
}
cout<<endl;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3556kb
input:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
output:
-1 -1
result:
wrong answer 1st lines differ - expected: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...9 90 91 92 93 94 95 96 97 98 99', found: '-1'