QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485338 | #7678. The Game | yaoy | WA | 3ms | 3888kb | C++20 | 2.3kb | 2024-07-20 16:36:36 | 2024-07-20 16:36:37 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
bool ok = true;
int dif = 0;
for (int i = n - 1, j = m - 1; j >= 0; j--, i--) {
ok &= (a[i] <= b[j]);
dif += b[j] - a[i];
}
if (!ok || dif > n - m) {
std::cout << -1 << "\n";
return;
}
int r = n - m - dif;
for (int i = 0; i < r; i++) {
ok &= (a[i] + 1 <= b[0]);
}
if (!ok) {
std::cout << -1 << "\n";
return;
}
std::vector<int> ans;
for (int i = 0; i < r; i++) {
ans.emplace_back(a[i]);
}
for (int j = 0, i = n - m; j < m; j++, i++) {
for (int v = a[i]; v < b[j]; v++) {
ans.emplace_back(v);
}
}
auto check = [&]() -> bool {
bool OK = true;
std::multiset<int> Sa(a.begin(), a.end()), Sb(b.begin(), b.end());
for (auto &x : ans) {
OK &= Sa.contains(x);
Sa.extract(x);
Sa.erase(Sa.begin());
Sa.insert(x + 1);
}
OK &= (Sa == Sb);
return OK;
};
auto output = [&]() {
std::cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) {
std::cout << ans[i] << " \n"[i == ans.size() - 1];
}
};
if (check()) {
output();
return;
}
ans.clear();
int cost = 0;
for (int i = r - 1; i >= cost && cost < r; i--) {
for (int v = a[i]; v < b[0] && cost < r && i >= cost; v++) {
cost++;
ans.emplace_back(v);
}
}
for (int j = 0, i = n - m; j < m; j++, i++) {
for (int v = a[i]; v < b[j]; v++) {
ans.emplace_back(v);
}
}
if (check()) {
output();
return;
}
std::cout << -1 << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
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: 3ms
memory: 3660kb
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 -1 ...
result:
wrong answer Jury has answer but participant has not (test case 2053)