QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789867 | #8034. Ban or Pick, What's the Trick | jielosc | WA | 1ms | 5620kb | C++20 | 1.3kb | 2024-11-27 22:20:19 | 2024-11-27 22:20:28 |
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 >= n * 2) 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) == 0) {
if(k1 + 1 <= k and n - (u / 2 - k2) - k1 >= 1) d = std::max(d, dfs(u + 1, k1 + 1, k2) + a[n - (u / 2 - k2) - k1]);
if(k2 + u/2 - k1 < n) d = std::max(d, dfs(u + 1, k1, k2));
} else {
if(k2 + 1 <= k and n - ((u+1)/2 - k1) - k2 >= 1) d = std::min(d, dfs(u + 1, k1, k2 + 1) - b[n - ((u+1)/2 - k1) - k2]);
if(k1 + u/2 - k2 < n) d = std::min(d, dfs(u + 1, k1, k2));
}
return d;
}
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);
cout << dfs(0, 0, 0) << 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
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5568kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
4 1 1 3 5 7 2 4 6 8
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5620kb
input:
4 2 4 6 7 9 2 5 8 10
output:
0
result:
wrong answer 1st lines differ - expected: '3', found: '0'