QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#418766#8034. Ban or Pick, What's the Trick_mjj#TL 3ms3600kbC++201.2kb2024-05-23 15:38:052024-05-23 15:38:05

Judging History

This is the latest submission verdict.

  • [2024-05-23 15:38:05]
  • Judged
  • Verdict: TL
  • Time: 3ms
  • Memory: 3600kb
  • [2024-05-23 15:38:05]
  • Submitted

answer

#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin() , v.end()
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long

using namespace std;

typedef long long LL;
typedef pair<int , int> PII;

const int N = 1e5 + 5;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
int a[N],b[N],n,k;
int dfs(int turn,int x,int y) {
    if(turn==2*n+1) return 0;
    if(turn&1) {
        int res=turn/2;
        int ret=res+x-y+1;
        int ans=-1e18;
        if(x+1<=k) ans=max(ans,dfs(turn+1,x+1,y)+a[ret]);
        ans=max(ans,dfs(turn+1,x,y));
        return ans;
    } else {
        int res=turn/2;
        int ret=res-x+y+1;
        int ans=1e18;
        if(y+1<=k) ans=min(ans,dfs(turn+1,x,y+1)-b[ret]);
        ans=min(ans,dfs(turn+1,x,y));
        return ans;
    }
}
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]; 
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    reverse(a+1,a+n+1);
    reverse(b+1,b+n+1);
    cout<<dfs(1,0,0)<<endl;
}

signed main(){
    ios;
    int T = 1;
    // cin >> T;
    while(T --){
        solve();
    }
    return 0;
}
/*
5
1 2
2 3
2 4
1 5
*/

詳細信息

Test #1:

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

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

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

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

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

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: