QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628711 | #8034. Ban or Pick, What's the Trick | lonelywolf# | TL | 4ms | 3812kb | C++20 | 1.1kb | 2024-10-10 21:50:55 | 2024-10-10 21:51:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(a.begin() + 1, a.end(), greater<>());
sort(b.begin() + 1, b.end(), greater<>());
function<int(int, int, int)> dfs = [&](int r, int x, int y) {
if (r == 2 * n) {
return 0LL;
}
if (r % 2 == 0) {
int mx = dfs(r + 1, x, y);
if (x < min(k, n) && x + (r + 1) / 2 - y < n) {
mx = max(mx, dfs(r + 1, x + 1, y) + a[x + (r + 1) / 2 - y + 1]);
}
// cerr << r << " " << x << " " << y << " " << mx << "\n";
return mx;
} else {
int mn = dfs(r + 1, x, y);
if (y < min(k, n) && y + (r + 1) / 2 - x < n) {
mn = min(mn, dfs(r + 1, x, y + 1) - b[y + (r + 1) / 2 - x + 1]);
}
// cerr << r << " " << x << " " << y << " " << mn << "\n";
return mn;
}
assert(false);
};
cout << dfs(0, 0, 0) << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
4 1 1 3 5 7 2 4 6 8
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 4ms
memory: 3792kb
input:
10 5 42 13 60 42 100 82 22 98 14 55 100 41 89 24 65 38 69 26 37 16
output:
41
result:
ok single line: '41'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
9 10 4 32 566 885 439 479 332 95 432 409 140 704 26 558 781 457 356 404
output:
58
result:
ok single line: '58'
Test #6:
score: -100
Time Limit Exceeded
input:
20 8 249 888 548 338 840 890 519 416 852 817 28 694 271 947 239 11 654 914 765 939 483 148 403 552 250 635 287 644 364 822 621 151 31 422 683 959 867 266 837 395