QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#254595 | #7678. The Game | sundage# | TL | 0ms | 0kb | C++17 | 1.3kb | 2023-11-18 13:22:18 | 2023-11-18 13:22:18 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<int>a(n + 1);
vector<int>b(m + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 1; j <= m; j++) {
cin >> b[j];
}
sort(a.begin() + 1, a.end());
sort(b.begin() + 1, b.end());
int res = 0;
for (int i = 1; i <= m; i++) {
if (b[i] < a[i + n - m]) {
cout << "-1" << endl;
return;
}
if (b[i] > a[i + n - m]) {
res += b[i] - a[i + n - m];
}
}
priority_queue<int, vector<int>, greater<int>>q1, q2;
for (int i = 1; i <= n - m; i++) {
q1.push(a[i]);
}
for (int i = n - m + 1; i <= n; i++) {
q2.push(a[i]);
}
int cnt = n - m - res;
vector<int>ans;
while (cnt) {
cnt--;
int x = q1.top();
ans.push_back(x);
q1.pop();
if (x + 1 >= q2.top()) {
q2.pop();
q2.push(x + 1);
cnt++;
}
}
for (int i = 1; i <= m; i++) {
int x = q2.top();
q2.pop();
if (x > b[i]) {
cout << "-1" << endl;
return;
} else {
for (; x < b[i];) {
ans.push_back(x);
x++;
}
}
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
cout << endl;
return;
}
signed main() {
ios::sync_with_stdio(false);
int tt = 1;
cin >> tt;
while (tt--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
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