QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666263 | #7678. The Game | Ashbourne | WA | 6ms | 3628kb | C++20 | 1.4kb | 2024-10-22 17:25:14 | 2024-10-22 17:25:26 |
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) {
cs++; tt--;
}
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: 6ms
memory: 3628kb
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:
wrong answer Wrong answer, the final sequence does not equal to B (test case 134)