Submission #994478

#TimeUsernameProblemLanguageResultExecution timeMemory
994478idiotcomputerFeast (NOI19_feast)C++11
4 / 100
81 ms1628 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pii pair<ll,ll> #define f first #define s second const int mxN = 3e5; int n,k; int a[mxN]; pii test(ll v){ pii dp[2]; pii dp2[2]; dp[0] = {0,0}; dp[1] = {0,0}; for (int i = 0; i < n; i++){ dp2[0] = max(dp[0],(pii){dp[1].f-v,dp[1].s+1}); dp2[1] = max((pii) {dp[0].f+a[i],dp[0].s}, (pii) {dp[1].f+a[i],dp[1].s}); swap(dp2,dp); } dp[1] = (pii) {dp[1].f-v,dp[1].s+1}; return max(dp[0],dp[1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; ll l = -1; ll r = 1e15; ll c; while (r-l>1){ c = (l+r)/2; if(test(c).s<=k) r = c; else l = c; } pii t = test(r); // cout << r << " -= " << t.f << " " << t.s << '\n'; cout << t.f - (t.s-k)*r << "\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...