This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "homecoming.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1;
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 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... |