#include "homecoming.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000000000
#define umax(x,y) x=max(x,(y))
#define pw(x) (1<<(x))
ll psum[205],psum2[205];
long long solve(int N, int K, int *A, int *B) {
vector< vector<ll> > dp[2];
for(int i=0;i<2;i++) {
dp[i].resize(N+2);
for(int j=0;j<N+2;j++) {
dp[i][j].resize(K+1);
}
}
for(int i=N;i>=1;i--) {
A[i]=A[i-1];
B[i]=B[i-1];
}
for(int i=1;i<=N;i++) {psum[i]=psum[i-1]+B[i];psum2[i]=psum2[i-1]+A[i];}
for(int i=1;i<=N+1;i++) for(int j=0;j<=min(i-1,K);j++) for(int t=0;t<2;t++) dp[t][i][j]=-inf;
dp[1][1][0]=0;
for(int i=1;i<=N;i++) {
for(int j=0;j<=min(i-1,K);j++) {
if(dp[1][i][j]!=-inf) {
if(i<N) umax(dp[1][i+1][min(K,j+(j==i-1))],dp[1][i][j]-B[i]+(i-K+1>=1?A[i-K+1]:0));
else {
int amount=max(0,min(j+1-K+1,K));
umax(dp[1][N+1][min(K,j+(j==i-1))],dp[1][i][j]-B[i]+psum2[i]-psum2[i-amount]);
}
umax(dp[0][i+1][j],dp[1][i][j]);
}
if(dp[0][i][j]!=-inf) {
if(i+K<=N) {
umax(dp[1][i+K][j],dp[0][i][j]+A[i]-(psum[i+K-1]-psum[i-1]));
}
else {
int amount=max(0,min(N+1-i,j+N+1-i-K+1));
umax(dp[1][N+1][j],dp[0][i][j]+psum2[i+amount-1]-psum2[i-1]-(psum[N]-psum[i-1]));
}
umax(dp[0][i+1][j],dp[0][i][j]);
}
}
}
for(int i=1;i<=N;i++) A[i-1]=A[i],B[i-1]=B[i];
ll res=0;
for(int i=0;i<=min(N,K);i++) {
umax(res,max(dp[0][N+1][i],dp[1][N+1][i]));
/* if(res==47) {
printf("%d\n%lld %lld\n",i,dp[0][N+1][i],dp[1][N+1][i]);
return res;
}*/
}
umax(res,psum2[N]-psum[N]);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Runtime error |
7 ms |
3556 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Runtime error |
7 ms |
3556 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
279 ms |
149464 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Runtime error |
7 ms |
3556 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |