QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276831 | #7678. The Game | Yu_Jie | WA | 1ms | 6120kb | C++14 | 1.8kb | 2023-12-06 11:29:49 | 2023-12-06 11:29:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
int n,m,a[N],b[N];
int read() {
int x=0,f=1; char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
return x*f;
}
void solve() {
n=read(); m=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) b[i]=read();
sort(a+1,a+n+1,[](int x,int y){return x>y;});
sort(b+1,b+m+1,[](int x,int y){return x>y;});
int x=0;
for(int i=1;i<=m;i++) {
if(a[i]>b[i]) {puts("-1"); return ;}
x+=b[i]-a[i];
}
if(x>n-m) {puts("-1"); return ;}
x=n-m-x;
multiset<int> s;
vector<int> ans;
for(int i=m+1;i<=n;i++) s.insert(a[i]);
int cur=m;
while(x&&*s.begin()<a[m]) {
int v=*s.begin();
if(x>1&&*next(s.begin())==v) {
while(cur&&a[cur]==b[cur]) cur--;
if(cur) {
a[cur]++;
s.erase(s.begin());
continue;
}
}
ans.push_back(v);
s.erase(s.begin());
s.insert(v+1);
s.erase(s.begin());
x--;
}
if(!x) {
for(int i=1;i<=m;i++)
for(int j=a[i];j<b[i];j++) ans.push_back(j);
}
else {
for(int i=1;i<=m;i++)
for(int j=a[i];j<b[i];j++) ans.push_back(j),s.erase(s.begin());
while(x) {
int v=*s.begin();
if(v==b[m]) {puts("-1"); return ;}
ans.push_back(v);
s.erase(s.begin());
s.insert(v+1);
s.erase(s.begin());
x--;
}
}
printf("%d\n",ans.size());
for(int i:ans) printf("%d ",i); puts("");
}
int main() {
for(int T=read();T--;) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
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 2 3 1 2 2 1 1 -1
result:
ok ok (6 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3716kb
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 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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok ok (7056 test cases)
Test #3:
score: 0
Accepted
time: 1ms
memory: 6120kb
input:
5880 4 2 1 1 1 1 1 1 4 2 1 1 1 1 1 2 4 2 1 1 1 1 1 3 4 2 1 1 1 1 1 4 4 2 1 1 1 1 1 5 4 2 1 1 1 1 1 6 4 2 1 1 1 1 1 7 4 2 1 1 1 1 2 2 4 2 1 1 1 1 2 3 4 2 1 1 1 1 2 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 7 -1 -1 -1 -1 -1 -1 3 1 1 2 2 1 2 -1 -1 -1 -1 ...
result:
wrong answer Wrong answer, number of operation is not correct (test case 11)