Submission #152036

#TimeUsernameProblemLanguageResultExecution timeMemory
152036souhhcongHomecoming (BOI18_homecoming)C++14
0 / 100
268 ms262148 KiB
#include <iostream> #include <homecoming.h> using namespace std; const int N = 2e6+2; int n, k, a[N], b[N]; long long dp[N], pref[N], ans = 0; long long get_sum(int l, int r) { if (l <= r) return pref[r] - pref[l-1]; else return get_sum(l,n-1) + get_sum(0,r); } long long solve(int N, int K, int *A, int *B) { pref[0] = B[0]; for (int i = 1; i < N; i++) { pref[i] = pref[i-1] + b[i]; } dp[0] = max(0LL,A[0]-get_sum(0,k-1)); for (int i = 1; i < N; i++) { if (i >= K) dp[i] = max(dp[i-1] + A[i] - B[(i+K-1)%N], dp[i-K] + A[i] - get_sum(i,(i+K-1)%N)); else dp[i] = dp[i-1] + A[i] - B[(i+K-1)%N]; } for (int i = 0; i < N; i++) ans = max(ans,dp[i]); //cout << dp[0] << ' ' << dp[1] << ' ' << dp[2] << endl; return ans; } /* int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; cout << solve(n,k,a,b); } */ /* 3 2 40 80 100 140 0 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...