This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "homecoming.h"
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
const ll oo = -1e18;
long long solve(int N, int K, int *A, int *B) {
int n = N,k = K;
ll ans = 0;
for(int rep=0;rep<2;++rep) {
// rep==0: include a[0] certainly, so extra cost beyond the boundary does not have to be counted.
// rep==1: doesn't matter if a[0] gets chosen or not.
ll dp[2] = {};
if(rep==0) dp[0] = oo;
ll cost=0;
for(int i=0;i<k;++i) cost+=B[i];
dp[1] = A[0]-cost;
for(int i=1;i<n;++i) {
cost-=B[i-1];
int extra=0;
if(i+k-1<n) {
extra = B[i+k-1];
} else if(rep==1) {
extra = B[i+k-1-n];
}
cost+=extra;
tie(dp[0],dp[1]) = make_pair(max(dp[0],dp[1]), A[i]+ max(dp[0]-cost,dp[1]-extra));
}
ans = max({ans,dp[0],dp[1]});
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |