QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#238539 | #7678. The Game | ucup-team073# | WA | 1ms | 8124kb | C++14 | 1.5kb | 2023-11-04 16:59:41 | 2023-11-04 16:59:43 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define debug puts("###");
using namespace std;
const int N=3e5+10;
int a[N],b[N],B[N];
inline void solve() {
int n,m;//puts("1");
scanf("%lld%lld",&n,&m);
for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
for (int i=n-m+1;i<=n;i++) scanf("%lld",&b[i]);
sort(a+1,a+n+1);
sort(b+n-m+1,b+n+1);
for (int i=n-m+1;i<=n;i++) if (a[i]>b[i]) {puts("-1");return ;}
int suma=0,sumb=0;
for (int i=n-m+1;i<=n;i++) suma+=a[i],sumb+=b[i];
int step=sumb-suma,minb=b[n-m+1];
if (step>n-m) {puts("-1");return ;}
priority_queue<int,vector<int>,greater<int> > q,q2;
for (int i=1;i<=n-m;i++) q.push(a[i]);
vector<int> v;
for (int i=n-m+1;i<=n;i++) if (a[i]!=b[i]) v.push_back(i);
int len=v.size();
for (int i=n-m+1,j=0;j<len;i++,j++) b[i]=b[v[j]],q2.push(a[v[j]]);
vector<int> ans;
for (int i=n-m,cnt=n-m+1;i>=1;i--) {
int x=q.top(),y=-1; q.pop();
if (!q2.empty()) y=q2.top();
if (x>=minb) {puts("-1");return ;}
if (x==y) {
q2.pop(); --step; ans.push_back(y);
if (y+1==b[cnt]) ++cnt;
else q2.push(y+1);
}
else {
q.push(x+1); ans.push_back(x); q.pop();
}
if (i-1==step) {
while (!q2.empty()) {
int y=q2.top(); q2.pop();
ans.push_back(y); if(y+1==b[cnt]) ++cnt;
else q2.push(y+1);
}
break;
}
}
len=ans.size();
printf("%lld\n",len);
for (int i=0;i<len;i++) printf("%lld ",ans[i]);if (len!=0) puts("");
}
signed main(void) {
int t; cin>>t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8124kb
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: 0ms
memory: 7868kb
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 ...
result:
wrong answer Jury has answer but participant has not (test case 2)