Submission #1117544

#TimeUsernameProblemLanguageResultExecution timeMemory
1117544vjudge1Feast (NOI19_feast)C++14
100 / 100
120 ms14020 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> dp[MAXN][2]; pair<ll, ll> solve(ll mid) { 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[N-1][0], dp[N-1][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...