Submission #578440

#TimeUsernameProblemLanguageResultExecution timeMemory
578440jeroenodbHomecoming (BOI18_homecoming)C++14
100 / 100
129 ms55416 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...