Submission #1102898

#TimeUsernameProblemLanguageResultExecution timeMemory
1102898Tenis0206Feast (NOI19_feast)C++11
100 / 100
103 ms12888 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int nmax = 3e5; int n,k; int v[nmax + 5], sp[nmax + 5]; pair<int,int> dp[nmax + 5]; pair<int,int> calculate(int c) { pair<int,int> Max = {0, 0}; dp[0] = {0, 0}; for(int i=1;i<=n;i++) { dp[i] = dp[i - 1]; if(Max.first + sp[i] - c > dp[i].first || (Max.first + sp[i] - c == dp[i].first && Max.second + 1 < dp[i].second)) { dp[i].first = Max.first + sp[i] - c; dp[i].second = Max.second + 1; } if(dp[i].first - sp[i] > Max.first || (dp[i].first - sp[i] == Max.first && dp[i].second < Max.second)) { Max.first = dp[i].first - sp[i]; Max.second = dp[i].second; } } return dp[n]; } int solve() { int st = 1; int dr = 1e14; while(st<=dr) { int mij = (st + dr) >> 1; pair<int,int> val = calculate(mij); if(val.second == k) { return val.first + k * mij; } if(val.second < k) { dr = mij - 1; } else { st = mij + 1; } } pair<int,int> val = calculate(st); return val.first + val.second * st; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) { cin>>v[i]; sp[i] = sp[i - 1] + v[i]; } cout<<solve()<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...