Submission #611903

#TimeUsernameProblemLanguageResultExecution timeMemory
611903amunduzbaevHomecoming (BOI18_homecoming)C++17
0 / 100
1085 ms24316 KiB
#ifndef EVAL #include "homecoming.h" #endif #include "bits/stdc++.h" using namespace std; typedef long long ll; ll reshay(int n, int k, deque<int> a, deque<int> b){ vector<ll> pa(n), pb(n), dp(n); 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]; } ll mx = 0, res = 0; for(int i=0;i<n;i++){ if(i >= k) mx = max(mx, dp[i - k] - pa[i - k] + pb[i - k]); if(i + 1 >= k){ dp[i] = mx - pb[i] + pa[i - k + 1]; } res = max(res, dp[i]); } return res; } /* 1 3 2 40 80 100 140 0 20 */ ll solve(int n, int k, int A[], int B[]){ deque<int> a, b; ll res = 0; for(int i=0;i<n;i++) a.push_back(A[i]), res += A[i]; for(int i=0;i<n;i++) b.push_back(B[i]), res -= B[i]; res = max(res, 0ll); for(int i=0;i<n;i++){ res = max(res, reshay(n, k, a, b)); a.push_back(a.front()); a.pop_front(); b.push_back(b.front()); b.pop_front(); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...