QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679393 | #7678. The Game | CangShuV# | WA | 31ms | 5800kb | C++23 | 2.4kb | 2024-10-26 17:30:52 | 2024-10-26 17:30:54 |
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;
}
sort(ar + 1, ar + 1 + n);
sort(br + 1, br + 1 + m);
int sum = 0;
vector<int> que;
for (int i = 1; i <= m; ++i) {
sum += -ar[n + 1 - i] + br[i];
que.emplace_back(ar[n + 1 - i]);
}
sort(que.begin(), que.end());
// cout << "sum:" << sum << ' ' << k << '\n'; // ft.
if (sum < 0) {
cout << "-1\n";
return;
}
vector<int> op;
// cout << "sum:" << 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 (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: 1ms
memory: 5800kb
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: 0
Accepted
time: 4ms
memory: 3536kb
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:
ok ok (7056 test cases)
Test #3:
score: 0
Accepted
time: 3ms
memory: 3852kb
input:
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1 -...
result:
ok ok (50000 test cases)
Test #11:
score: -100
Wrong Answer
time: 14ms
memory: 3624kb
input:
25872 6 3 1 1 1 1 1 1 1 1 1 6 3 1 1 1 1 1 1 1 1 2 6 3 1 1 1 1 1 1 1 1 3 6 3 1 1 1 1 1 1 1 1 4 6 3 1 1 1 1 1 1 1 1 5 6 3 1 1 1 1 1 1 1 1 6 6 3 1 1 1 1 1 1 1 2 2 6 3 1 1 1 1 1 1 1 2 3 6 3 1 1 1 1 1 1 1 2 4 6 3 1 1 1 1 1 1 1 2 5 6 3 1 1 1 1 1 1 1 2 6 6 3 1 1 1 1 1 1 1 3 3 6 3 1 1 1 1 1 1 1 3 4 6 3 1 1 ...
output:
-1 -1 -1 3 1 2 3 -1 -1 -1 3 1 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 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 3 2 3 4 -1 -1 -1 3 1 2 3 -1 -1 3 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 1 1 1 3 1 1 2 -1 -1 -1 -1 -1 ...
result:
wrong answer Wrong answer, the final sequence does not equal to B (test case 640)