Submission #1079938

#TimeUsernameProblemLanguageResultExecution timeMemory
107993812345678Feast (NOI19_feast)C++17
100 / 100
96 ms5840 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=3e5+5; ll n, k, qs[nx]; pair<ll, ll> solve(ll x) { pair<ll, ll> mx, dp; for (int i=1; i<=n; i++) { dp=max(dp, {mx.first+qs[i]-x, mx.second-1}); mx=max(mx, {dp.first-qs[i], dp.second}); } return dp; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>k; for (int i=1; i<=n; i++) cin>>qs[i], qs[i]+=qs[i-1]; ll l=0, r=3e14+5; while (l<r) { ll md=(l+r)/2; if (-solve(md).second>k) l=md+1; else r=md; } cout<<solve(l).first-solve(l).second*l; }
#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...