QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666499 | #7678. The Game | Ashbourne | WA | 4ms | 3668kb | C++14 | 1.5kb | 2024-10-22 18:48:45 | 2024-10-22 18:48:48 |
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--;
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);
mp[k + 1]++;
}
if(!flag || tt < 0){
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: 100
Accepted
time: 0ms
memory: 3668kb
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: 4ms
memory: 3572kb
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)