Submission #1117543

#TimeUsernameProblemLanguageResultExecution timeMemory
1117543vjudge1Feast (NOI19_feast)C++14
41 / 100
1047 ms25616 KiB
#include <bits/stdc++.h> using ll = long long; using namespace std; template<typename T> void umax(T &a, const T b) {a = max(a, b);} template<typename T> void umin(T &a, const T b) {a = min(a, b);} constexpr int MAXN = 3e5 + 1; int N, K; int A[MAXN]; pair<ll, ll> solve(ll mid) { vector<vector<pair<ll, ll>>> dp(N, vector<pair<ll, ll>>(2)); dp[0][0] = {0, 0}; dp[0][1] = {A[0] - mid, 1}; for (int i = 1; i < N; ++i) { dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = max( make_pair(dp[i-1][0].first - mid + A[i], dp[i-1][0].second + 1), make_pair(dp[i-1][1].first + A[i], dp[i-1][1].second) ); } return max(dp.back()[0], dp.back()[1]); } int main() { cin.tie(0)->sync_with_stdio(false); cin >> N >> K; for (int i = 0; i < N; ++i) cin >> A[i]; ll l = 0, r = 1e18; while (l < r) { ll mid = (l + r + 1) >> 1; if (solve(mid).second >= K) l = mid; else r = mid - 1; } cout << solve(l).first + K * l; 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...