QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679131 | #7678. The Game | CangShuV# | WA | 4ms | 3780kb | C++23 | 2.6kb | 2024-10-26 16:57:05 | 2024-10-26 16:57:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int ar[N], br[N];
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> ar[i];
for (int i = 1; i <= m; ++i)
cin >> br[i];
int k = n - m;
multiset<int> a, b;
for (int i = 1; i <= n; ++i)
a.insert(ar[i]);
for (int i = 1; i <= m; ++i)
b.insert(br[i]);
if (*a.rbegin() > *b.rbegin()) {
cout << "-1\n";
return;
}
vector<int> op;
int sum = 0;
for (auto &it : b) {
auto tmp = a.upper_bound(it);
if (tmp == a.begin()) {
cout << "-1\n";
return;
}
--tmp;
sum += it - (*tmp);
}
// cout << sum << ' ' << k << '\n'; // ft.
if (sum > k) {
cout << "-1\n";
return;
}
int bm = *b.begin();
sum = k - sum;
while (sum--) {
int t = *a.begin();
a.extract(t);
op.emplace_back(t);
a.insert(t + 1);
if (t + 1 > bm) {
cout << "-1\n";
return;
}
a.extract(*a.begin());
}
while (b.size()) {
while (a.find(*b.begin()) == a.end()) {
int t = *b.begin();
auto acc = a.upper_bound(t);
if (acc == a.begin()) {
cout << "-1\n";
return;
}
--acc;
a.extract(*acc);
op.emplace_back(*acc);
a.insert((*acc) + 1);
a.extract(*a.begin());
}
a.extract(*b.begin());
b.extract(*b.begin());
}
// if (b.size()) {
// cout << "-1\n";
// return;
// }
// while (a.size()) {
// int t = *a.begin();
// a.extract(t);
// op.emplace_back(t);
// a.insert(t + 1);
// if (t + 1 > bm) {
// cout << "-1\n";
// return;
// }
// a.extract(*a.begin());
// }
if (op.size() < n - m) {
int cnt = n - m - (int)op.size();
while (cnt--) {
int t = *a.begin();
a.extract(t);
op.emplace_back(t);
a.insert(t + 1);
if (t + 1 > bm) {
cout << "-1\n";
return;
}
a.extract(*a.begin());
}
}
cout << op.size() << '\n';
for (auto &it : op) {
cout << it << ' ';
}
cout << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
while (n--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
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 2 3 2 2 1 1 -1
result:
ok ok (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3604kb
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 Jury has answer but participant has not (test case 63)