QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672061 | #7678. The Game | Sred | WA | 8ms | 5692kb | C++17 | 1.7kb | 2024-10-24 15:29:29 | 2024-10-24 15:29:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e6 + 5;
const int inf = 2e6;
int n,m;
int a[maxn],b[maxn];
void solve(){
cin >> n >> m;
int ans = 0;
for(int i = 1 ;i <= n ;i ++)
cin >> a[i];
for(int i = 1 ;i <= m ;i ++)
cin >> b[i];
priority_queue<int,vector<int>,greater<int> > q,h;
sort(a + 1, a + 1 + n);
sort(b + 1,b + 1 + m);
int t = n - m;
for(int i = 1;i <= n ;i ++){
if(i <= t) q.push(a[i]);
else{
if(a[i] > b[i - t]){
cout << -1 << endl;
return;
}
h.push(a[i]);ans += b[i - t] - a[i];
}
}
if(ans > t){
cout << -1 << endl;
return;
}
vector<int> nums;
int t1 = t - ans;
//cout << t1 << endl;
while(t1--){
int k = q.top();
q.pop();
nums.push_back(k);
if(k + 1 > h.top()){
int t = h.top();
h.pop();
h.push(k + 1);
q.push(t);
if(k + 1 <= b[1]) t1 ++;
}
else
q.push(k + 1);
q.pop();
}
for(int i = 1;i <= m ;i ++){
a[i] = h.top();
h.pop();
if(a[i] > b[i]){
cout << -1 << endl;
return;
}
while(b[i] > a[i]){
int k = q.top();
q.pop();
if(k + 1 > b[i]){
cout << - 1 << endl;
return;
}
q.push(k + 1);
q.pop();
nums.push_back(a[i]);
a[i] ++;
}
}
cout << nums.size() <<endl;
for(auto it : nums){
cout << it <<" ";
}
cout << endl;
}
signed main() {
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5692kb
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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1 3 4 4 2 1 1 1 1 3 5 4 2 1 1 1 1 3 6 4 2 1 1 1 1 3 7 4 2 1 1...
output:
-1 1 1 2 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 2 2 3 -1 -1 -1 2 1 1 2 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 2 3 4 -1 -1 -1 2 1 1 2 1 3 -1 -1 -1 2 1 2 -1 -1 -1 -1 -1 -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 2)