Submission #861660

#TimeUsernameProblemLanguageResultExecution timeMemory
861660AiperiiiHomecoming (BOI18_homecoming)C++17
100 / 100
111 ms102484 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...