Submission #578443

#TimeUsernameProblemLanguageResultExecution timeMemory
578443jeroenodbHomecoming (BOI18_homecoming)C++14
100 / 100
122 ms15948 KiB
#include "homecoming.h" #include "bits/stdc++.h" 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...