Submission #612547

#TimeUsernameProblemLanguageResultExecution timeMemory
612547amunduzbaevHomecoming (BOI18_homecoming)C++17
31 / 100
145 ms21228 KiB
#ifndef EVAL #include "homecoming.h" #endif #include "bits/stdc++.h" using namespace std; typedef long long ll; const int N = 2e5 + 5; ll dp[N][2], pa[N], pb[N]; ll solve(int n, int k, int a[], int b[]){ for(int i=0;i<n;i++){ pa[i] = a[i]; if(i) pa[i] += pa[i-1]; pb[i] = b[i]; if(i) pb[i] += pb[i-1]; } memset(dp, 254, sizeof dp); dp[0][1] = a[0] - pb[k - 1]; for(int i=1;i<n;i++){ dp[i][0] = max(dp[i-1][1], dp[i-1][0]); dp[i][1] = max(dp[i-1][1] + a[i] - (i + k - 1 < n ? b[i + k - 1] : 0), dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1])); } ll res = max(dp[n - 1][0], dp[n - 1][1]); memset(dp, 254, sizeof dp); dp[0][0] = 0; for(int i=1;i<n;i++){ dp[i][0] = max(dp[i-1][1], dp[i-1][0]); dp[i][1] = max(dp[i-1][1] + a[i] - b[(i + k - 1) % n], dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1] + (i + k > n ? pb[i + k - 1 - n] : 0))); } res = max({res, dp[n - 1][0], dp[n - 1][1]}); return res; } /* 1 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...