Submission #643297

#TimeUsernameProblemLanguageResultExecution timeMemory
643297SirCovidThe19thFeast (NOI19_feast)C++17
30 / 100
361 ms13892 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define f first #define s second int n, k, A[300005]; pll dp[300005][2]; pll better(pll a, pll b){ if (a.f == b.f) return (a.s < b.s ? a : b); return (a.f > b.f ? a : b); } bool solve(ll lmb){ dp[0][0] = {0, 0}; dp[0][1] = {-1e18, 0}; for (int i = 1; i <= n; i++){ dp[i][0] = better(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = better({dp[i - 1][0].f + A[i] - lmb, dp[i - 1][1].s + 1}, {dp[i - 1][1].f + A[i], dp[i - 1][1].s}); } return better(dp[n][0], dp[n][1]).s <= k; } int main(){ cin >> n >> k; for (int i = 1; i <= n; i++) cin >> A[i]; ll L = 0, H = 1e18; while (L < H){ ll M = (L + H) / 2; solve(M) ? H = M : L = M + 1; } solve(L); pll res = better(dp[n][0], dp[n][1]); cout<<res.f + L * k<<"\n"; }
#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...