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 ll long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
const int N=2e6+6;
ll dp[N][2];
ll solve(int n,int k,int a[],int b[]){
vector <ll> pr;
ll sum=0;
for(int i=0;i<n;i++){
sum+=b[i];
pr.push_back(sum);
}
dp[0][0]=-1e18;
dp[0][1]=a[0]-pr[k-1];
for(int i=1;i<n;i++){
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
ll val1=dp[i-1][1]+a[i];
if(i+k-1<n){
val1-=b[i+k-1];
}
ll val2=dp[i-1][0]+a[i]-pr[min(i+k-1,n-1)]+pr[i-1];
dp[i][1]=max(val1,val2);
}
ll res1=max(dp[n-1][0],dp[n-1][1]);
dp[0][0]=0;
dp[0][1]=-1e18;
for(int i=1;i<n;i++){
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
ll val1=dp[i-1][1]+a[i]-b[(i+k-1)%n];
ll val2=dp[i-1][0]+a[i]-pr[min(i+k-1,n-1)]+pr[i-1];
if(i+k-1>n-1){
val2-=pr[i+k-1-n];
}
dp[i][1]=max(val1,val2);
}
ll res2=max(dp[n-1][0],dp[n-1][1]);
return max(res1,res2);
}
# | 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... |