Submission #984853

#TimeUsernameProblemLanguageResultExecution timeMemory
984853IBoryFeast (NOI19_feast)C++17
100 / 100
141 ms15440 KiB
#include <bits/stdc++.h> #define pii pair<ll, ll> typedef long long ll; using namespace std; const int MAX = 300003; ll A[MAX]; pii dp[MAX][2]; const pii operator+(const pii a, const pii b) { return {a.first + b.first, a.second + b.second}; } pii Check(ll N, pii p) { dp[0][0] = {0, 0}; dp[0][1] = {-1e18, 0}; for (int i = 1; i <= N; ++i) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(dp[i - 1][1] + pii{A[i], 0}, dp[i - 1][0] + pii{A[i], 1} + p); } return max(dp[N][0], dp[N][1]); } int main() { ios::sync_with_stdio(0); cin.tie(0); ll N, K; cin >> N >> K; for (int i = 1; i <= N; ++i) cin >> A[i]; ll l = 0, r = 1e15; while (l + 1 < r) { ll mid = (l + r) >> 1; pii p = Check(N, pii{-mid, 0}); (p.second < K ? r : l) = mid; } pii t = Check(N, pii{-l, 0}); ll ans = t.first + t.second * l; cout << ans; 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...