QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747490 | #8034. Ban or Pick, What's the Trick | slmhh# | TL | 2ms | 3712kb | C++23 | 1.5kb | 2024-11-14 17:18:53 | 2024-11-14 17:18:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int N = 1e5 + 10,mod = 998244353;
ll n,k,a[N],b[N],ca[13],cb[13];
ll dfs(ll i,ll j,ll ai,ll bj,ll h){
ll temp;
if(h == 2 * n){
ll ta = 0;
for(int l = 1;l <= k;l++){
ta += ca[l] - cb[l];
// cout << ca[l] << " " << cb[l] << "\n";
}
// cout << "\n";
return ta;
}
if(h & 1LL){ //b;
if(i <= n)
temp = dfs(i + 1,j,ai,bj,h + 1);
if(bj < k && j <= n){
cb[bj + 1] = b[j];
if(i <= n) temp = min(temp,dfs(i,j + 1,ai,bj + 1,h + 1));
else temp = dfs(i,j + 1,ai,bj + 1,h + 1);
cb[bj + 1] = 0;
}
}
else{ //a
if(j <= n)
temp = dfs(i,j + 1,ai,bj,h + 1);
if(ai < k && i <= n){
ca[ai + 1] = a[i];
if(j <= n) temp = max(temp,dfs(i + 1,j,ai + 1,bj,h + 1));
else temp = dfs(i + 1,j,ai + 1,bj,h + 1);
ca[ai + 1] = 0;
}
}
return temp;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll T = 1;
// cin >> T;
while(T--){
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,greater<ll>());
sort(b + 1,b + n + 1,greater<ll>());
cout << dfs(1,1,0,0,0) << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
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: 3712kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3636kb
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: 1ms
memory: 3708kb
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