Submission #1109998

#TimeUsernameProblemLanguageResultExecution timeMemory
1109998NoMercyFeast (NOI19_feast)C++17
100 / 100
156 ms26852 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int32_t main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, K; cin >> N >> K; vector<ll> arr(N + 1, 0); for (int i = 1;i <= N;i ++) cin >> arr[i]; vector<vector<pair<ll, ll>>> dp(N + 1, {{0, 0}, {0, 0}}); auto calculate = [&](ll mid) -> void { dp[1][0] = {0, 0}; dp[1][1] = {arr[1] - mid, 1}; for (int i = 2;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 + arr[i] - mid, dp[i - 1][0].second + 1), make_pair(dp[i - 1][1].first + arr[i], dp[i - 1][1].second)); } }; ll lo = 0, hi = 1e16 + 6789; while (lo + 1 < hi) { ll mid = (lo + hi) / 2LL; calculate (mid); if (max(dp[N][0], dp[N][1]).second < K) { hi = mid; } else { lo = mid; } } calculate (lo); cout << max(dp[N][0], dp[N][1]).first + lo * 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...