QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789416 | #8034. Ban or Pick, What's the Trick | lmx111 | WA | 1ms | 7724kb | C++20 | 1.7kb | 2024-11-27 20:17:34 | 2024-11-27 20:17:34 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
using std::cin;
using std::cout;
const char endl = '\n';
const int maxn = (int)1.1E5;
int n, k;
int a[maxn], b[maxn];
int dp[maxn * 2][13][13];
bool vis[maxn * 2][11][11];
int dfs(int u, int k1, int k2) {
if (u == 0 or (u + 1) / 2 < k1 or u / 2 < k2) return 0;
if((u+1)/2 - k1 + k2 > n) return 0;
if(u/2 - k2 + k1 > n) return 0;
if (vis[u][k1][k2]) return dp[u][k1][k2];
vis[u][k1][k2] = 1;
int &d = dp[u][k1][k2];
if (u & 1) {
if (k1 == 0) return d = dfs(u - 1, k1, k2);
if(u == k1 + k2) return d = dfs(u - 1, k1 - 1, k2) + a[n - (u / 2 - k2) - (k1 - 1)];
return d = std::min(dfs(u - 1, k1, k2), dfs(u - 1, k1 - 1, k2) + a[n - (u / 2 - k2) - (k1 - 1)]);
} else {
if (k2 == 0) return d = dfs(u - 1, k1, k2);
if(u == k1 + k2) return d = dfs(u - 1, k1, k2 - 1) - b[n - (u / 2 - k1) - (k2 - 1)];
return d = std::max(dfs(u - 1, k1, k2), dfs(u - 1, k1, k2 - 1) - b[n - (u / 2 - k1) - (k2 - 1)]);
}
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
std::sort(a + 1, a + 1 + n);
std::sort(b + 1, b + 1 + n);
int ans = 0;
for (int k1 = 0; k1 <= std::min(n, k); ++k1) {
// cout << dfs(n * 2, k1, k1) << endl;
ans = std::max(ans, dfs(n * 2, k1, k1));
}
cout << ans << endl;
}
int32_t main() {
#ifndef _DEBUG
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int tc = 1;
// std::cin >> tc;
while (tc--) solve();
#ifdef _DEBUG
std::cout << std::endl;
std::cout << "Time used: " << clock() << "ms" << std::endl;
system("pause");
return 0;
#endif
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5696kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5564kb
input:
4 1 1 3 5 7 2 4 6 8
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
input:
10 5 42 13 60 42 100 82 22 98 14 55 100 41 89 24 65 38 69 26 37 16
output:
32
result:
wrong answer 1st lines differ - expected: '41', found: '32'