QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257991 | #7678. The Game | daydream# | WA | 3ms | 3580kb | C++20 | 1.3kb | 2023-11-19 14:13:21 | 2023-11-19 14:13:21 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define eb emplace_back
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int infi=1e9;
int n,m;
void solve()
{
cin>>n>>m;vector<int> a(n+1,0),b(m+1,0);
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=1;i<=m;++i) cin>>b[i];
sort(a.begin()+1,a.end(),greater<int>());
sort(b.begin()+1,b.end(),greater<int>());
LL sum=0;multiset<int> st1,st2;
for(int i=1;i<=m;++i)
{
if(a[i]>b[i]) return cout<<"-1\n",void();
st1.insert(a[i]);sum+=b[i]-a[i];
}
if(sum>n-m) return cout<<"-1\n",void();
for(int i=1;i<=n;++i) st2.insert(a[i]);
vector<int> ans;
while(sum<n-m)
{
int x=*st2.begin();st2.erase(st2.find(x));
ans.eb(x);
st2.insert(++x);
if(x>*st1.begin())
{
sum--;
if(sum<0) return cout<<"-1\n",void();
st1.erase(st1.begin());
st1.insert(x);
}
st2.erase(st2.begin());
--n;
}
for(int i=m;i;--i) a[i]=*st1.begin(),st1.erase(st1.begin());
for(int i=1;i<=m;++i)
for(int j=a[i];j<b[i];++j)
ans.eb(j);
cout<<ans.size()<<'\n';
for(auto x:ans) cout<<x<<' ';
cout<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int TT=1;
cin>>TT;
for(;TT;--TT) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: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 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 3 1 1 2 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 3 1 1 3 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 ...
result:
wrong answer Wrong answer, number of operation is not correct (test case 31)