Submission #984881

#TimeUsernameProblemLanguageResultExecution timeMemory
984881IBoryFeast (NOI19_feast)C++17
100 / 100
140 ms15236 KiB
#include <bits/stdc++.h> #define pii pair<ll, ll> typedef long long ll; using namespace std; const int MAX = 1000007; 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 = 1e17; 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{-r, 0}); ll ans = (__int128_t)t.first + (__int128_t)t.second * r; 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...