This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] = max(0ll, mx - pb[i] + pa[i - k + 1]);
if(i) dp[i] = max(dp[i], dp[i-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 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... |