QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666462 | #7678. The Game | Ashbourne | WA | 0ms | 3596kb | C++14 | 1.5kb | 2024-10-22 18:36:54 | 2024-10-22 18:37:03 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
void solve(){
// auto add = [&](int &x, int y)->void{
// x += y;
// };
// auto check = [&]()->bool{
//
// }
cin >> n >> m;
int sum1 = 0, sum2 = 0;
map<int, int>mp;
vector<int> a(n + 1), b(m + 1);
for(int i = 1; i <= n; ++ i){
int x; cin >> x;
a[i] = x;
mp[x]++;
}
for(int i = 1; i <= m; ++ i){
cin >> b[i];
sum1 += b[i];
}
sort(a.begin() + 1, a.begin() + n + 1);
sort(b.begin() + 1, b.begin() + m + 1);
for(int i = n - m + 1; i <= n; ++ i){
sum2 += a[i];
}
int tt = sum1 - sum2;
if(sum1 - sum2 > n - m || tt < 0){
cout << -1 << endl;
return;
}
vector<int> ans;
int cs = n - m - sum1 + sum2, u = 0;
bool flag = 1;
for(int i = 1; i <= cs; ++ i){
// if(a[n - m + 1] > b[1]){
// flag = 0;
// break;
// }
auto [k, v] = *mp.begin();
a[i + v - 1] ++;
if(i + v - 1 >= n - m + 1) {
tt--;
if(a[i + v - 1] > b[i + v - 1 - n + m]){
flag = 0;
break;
}
}
ans.push_back(k);
mp[k]--; if(mp[k] == 0) mp.erase(k);
mp[k + 1]++;
auto [k1, v1] = *mp.begin();
mp[k1]--;
if(mp[k1] == 0) mp.erase(k1);
}
if(!flag){
cout << -1 << endl;
}else{
cout << tt + cs << endl;
for(auto x: ans) cout << x << " ";
for(int i = n - m + 1; i <= n; ++ i){
for(int j = a[i]; j < b[i - n + m]; ++ j) cout << j << " ";
}
cout << endl;
}
}
signed main(){
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--) solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
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 4 1 1 2 3 1 1 2 1 1
result:
wrong answer Wrong answer, number of operation is not correct (test case 4)