#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[2000005],psum2[2000005];
vector<ll> dp[2][2000005];
long long solve(int N, int K, int *A, int *B) {
for(int i=0;i<2;i++) {
for(int j=0;j<N+2;j++) {
dp[i][j].resize(K+1);
}
}
for(int i=1;i<=N;i++) {psum[i]=psum[i-1]+B[i-1];psum2[i]=psum2[i-1]+A[i-1];}
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-1]+(i-K+1>=1?A[i-K+1-1]:0));
else {
int amount=max(0,min(j+1,K));
umax(dp[1][N+1][min(K,j+(j==i-1))],dp[1][i][j]-B[i-1]+psum2[i-K+amount]-psum2[i-K]);
}
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-1]-(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]);
}
}
}
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]));
}
umax(res,psum2[N]-psum[N]);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
94328 KB |
Output is correct |
2 |
Correct |
119 ms |
97508 KB |
Output is correct |
3 |
Correct |
114 ms |
97508 KB |
Output is correct |
4 |
Correct |
114 ms |
97508 KB |
Output is correct |
5 |
Correct |
92 ms |
97508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
94328 KB |
Output is correct |
2 |
Correct |
119 ms |
97508 KB |
Output is correct |
3 |
Correct |
114 ms |
97508 KB |
Output is correct |
4 |
Correct |
114 ms |
97508 KB |
Output is correct |
5 |
Correct |
92 ms |
97508 KB |
Output is correct |
6 |
Runtime error |
796 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
285 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
94328 KB |
Output is correct |
2 |
Correct |
119 ms |
97508 KB |
Output is correct |
3 |
Correct |
114 ms |
97508 KB |
Output is correct |
4 |
Correct |
114 ms |
97508 KB |
Output is correct |
5 |
Correct |
92 ms |
97508 KB |
Output is correct |
6 |
Runtime error |
796 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |