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<iostream>
#include<vector>
using namespace std;
const int n=2e6+2;
const long long inf=1e18+2;
long long dp[n][2][2],sum[n]; //co chon khong , loai nao
long long solve(int N,int K,int* A,int* B){
int i;
for(i=0;i<N;i++){
sum[i]=B[i];
if(i){
sum[i]+=sum[i-1];
}
}
dp[0][0][0]=0;
dp[0][1][1]=A[0]-sum[K-1];
// cout<<dp[0][1][1]<<endl;
for(i=1;i<N;i++){
dp[i][0][0]=max(dp[i-1][0][0],dp[i-1][1][0]);
dp[i][0][1]=max(dp[i-1][0][1],dp[i-1][1][1]);
if(i+K-1<N){
dp[i][1][0]=max(dp[i-1][1][0]+A[i]-B[i+K-1],dp[i-1][0][0]+A[i]-sum[i+K-1]+sum[i-1]);
dp[i][1][1]=max(dp[i-1][1][1]+A[i]-B[i+K-1],dp[i-1][0][1]+A[i]-sum[i+K-1]+sum[i-1]);
}
else{
dp[i][1][0]=max(dp[i-1][1][0]+A[i]-B[i+K-1-N],dp[i-1][0][0]+A[i]-sum[i+K-1-N]-sum[N-1]+sum[i-1]);
dp[i][1][1]=max(dp[i-1][1][1]+A[i],dp[i-1][0][1]+A[i]-sum[N-1]+sum[i-1]);
}
//cout<<dp[i][1][1]<<endl;
}
//cout<<dp[n-1][1][1]<<endl;
return max(max(dp[N-1][0][1],dp[N-1][1][0]),max(dp[N-1][1][1],dp[N-1][0][0]));
}
//signed main(){
// int A[]={40},B[]={20};
// cout<<solve(1,1,A,B);
//}
# | 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... |