Submission #1102947

#TimeUsernameProblemLanguageResultExecution timeMemory
1102947filiptudose7Feast (NOI19_feast)C++11
100 / 100
95 ms12368 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int sp[300005],v[300005]; pair <int,int> dp[300005]; int n,k; pair <int,int> calc(int lambda) { pair<int,int> Max={0,0}; for(int i=1; i<=n; ++i) { dp[i]=dp[i-1]; if(Max.first+sp[i]-lambda>dp[i].first || (Max.first+sp[i]-lambda==dp[i].first && Max.second+1<dp[i].second)) { dp[i].first=Max.first+sp[i]-lambda; dp[i].second=Max.second+1; } if(dp[i].first>Max.first+sp[i] || (dp[i].first==Max.first+sp[i] && 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=3e14; while(st<=dr) { int mij=(st+dr)/2; pair<int,int> val=calc(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=calc(st); return val.first+val.second*st; } signed main() { ///freopen("feast.in","r",stdin); ///freopen("feast.out","w",stdout); cin.sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1; i<=n; ++i)cin>>v[i]; for(int i=1; i<=n; ++i)sp[i]=sp[i-1]+v[i]; cout<<solve(); 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...