QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662225#8034. Ban or Pick, What's the TrickcrychicTL 3ms5628kbC++171.6kb2024-10-20 22:03:432024-10-20 22:03:47

Judging History

This is the latest submission verdict.

  • [2024-10-20 22:03:47]
  • Judged
  • Verdict: TL
  • Time: 3ms
  • Memory: 5628kb
  • [2024-10-20 22:03:43]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int INF = 1e9;
int dp[2 * N][15][15];
int a[N],b[N];
int n,k;
int dfs(int dep,int l,int r){
    if(dep == 2 * n + 1)return 0;
    if(dp[dep][l][r] != -INF) return dp[dep][l][r];
    int lval = (dep - 1) / 2 + l - r, rval = dep  / 2 + r - l;
    if(dep & 1){
        int res = -INF;
        res = max(res,dfs(dep + 1,l,r));
        if(lval >= 0 && lval + 1 <= n && l + 1 <= k)res = max(res,dfs(dep + 1,l + 1,r) + a[lval + 1]);
        // cout << dep << ' ' << l << ' ' << r << ' ' << res << '\n';
        return res;
    }else {
        int res = INF;
        res = min(res,dfs(dep + 1,l,r));
        if(rval >= 0 && rval + 1 <= n && r + 1 <= k)res = min(res,dfs(dep + 1,l,r + 1) - b[rval + 1]);
        return res;
    }
}

void solve() {
    // int n;
    cin >> n >> k;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    for(int i = 1;i <= n;i ++) cin >> b[i];
    for(int i = 0;i <= 2 * n;i ++){
        for(int j = 0;j <= k;j ++){
            for(int jj = 0;jj <= k;jj ++){
                dp[i][j][jj] = -INF;
            }
        }
    }
    sort(a + 1,a + n + 1,[&](const int x,const int y)->bool {
        return x > y;
    });
    sort(b + 1,b + n + 1,[&](const int x,const int y)->bool {
        return x > y;
    });
    cout << dfs(1,0,0) << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    // cin >> t;
    while(t -- ) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5604kb

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: 5596kb

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 3ms
memory: 5620kb

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: 5628kb

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

output:


result: