QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317104 | #8034. Ban or Pick, What's the Trick | ship2077 | WA | 1ms | 5536kb | C++14 | 1.0kb | 2024-01-28 15:17:42 | 2024-01-28 15:17:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=1e5+5,M=22;
int n,k,a[N],b[N],dp[M][M][M][M],vis[M][M][M][M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int dfs(int x,int y,int dx,int dy){
if (x>n&&y>n) return 0;
if (vis[x][y][dx][dy]) return dp[x][y][dx][dy];
vis[x][y][dx][dy]=1;int ans;
if (x+y&1){
ans=INT_MAX;
if (x<=n) ans=min(ans,dfs(x+1,y,dx,dy));
if (y<=n) ans=min(ans,(dy<=k?-b[y]:0)+dfs(x,y+1,dx,dy+1));
}
else{
ans=-INT_MAX;
if (x<=n) ans=max(ans,(dx<=k?a[x]:0)+dfs(x+1,y,dx+1,dy));
if (y<=n) ans=max(ans,dfs(x,y+1,dx,dy));
}
return dp[x][y][dx][dy]=ans;
}
int main(){
n=read();k=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) b[i]=read();
sort(a+1,a+n+1,greater<int>());
sort(b+1,b+n+1,greater<int>());
n=min(n,k<<1);printf("%d\n",dfs(1,1,1,1));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3776kb
input:
2 1 3 6 2 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3996kb
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: 3928kb
input:
4 2 4 6 7 9 2 5 8 10
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4328kb
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: 4184kb
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: 0
Accepted
time: 1ms
memory: 5056kb
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:
1201
result:
ok single line: '1201'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 5536kb
input:
100 10 9813 7151 1299 6277 9002 7359 770 1582 3909 9113 1937 3436 846 9841 3378 5437 9443 9148 6862 6832 1910 1365 1328 26 7245 9468 6087 5828 8993 3378 6200 7242 6495 6783 7275 9837 5162 2140 3721 1586 7559 3721 9268 7186 1615 6648 5631 5752 3712 7856 7938 5414 9197 5259 3319 3616 3257 5880 2448 74...
output:
2056
result:
wrong answer 1st lines differ - expected: '2174', found: '2056'