제출 #1017824

#제출 시각아이디문제언어결과실행 시간메모리
1017824vjudge1Feast (NOI19_feast)C++17
100 / 100
177 ms15188 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ld long double #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) signed main() { ios_base::sync_with_stdio(0);cin.tie(0); int n, k; cin >> n >> k; vector<int> A(n + 1); for (int i = 1; i <= n; i++) { cin >> A[i]; } int l = 0, r = 1e18, res = 0; while (l <= r) { int md = (l + r) / 2; vector<array<array<int, 2>, 2>> dp(n + 1); dp[0][1][0] = -md, dp[0][1][1] = 1; for (int i = 1; i <= n; i++) { dp[i][1][0] = -md, dp[i][1][1] = 1; if (dp[i - 1][0][0] - md + A[i] > dp[i][1][0]) { dp[i][1][0] = dp[i - 1][0][0] - md + A[i]; dp[i][1][1] = dp[i - 1][0][1] + 1; } if (dp[i - 1][1][0] + A[i] > dp[i][1][0]) { dp[i][1][0] = dp[i - 1][1][0] + A[i]; dp[i][1][1] = dp[i - 1][1][1]; } if (dp[i - 1][0][0] > dp[i][0][0]) { dp[i][0][0] = dp[i - 1][0][0]; dp[i][0][1] = dp[i - 1][0][1]; } if (dp[i - 1][1][0] > dp[i][0][0]) { dp[i][0][0] = dp[i - 1][1][0]; dp[i][0][1] = dp[i - 1][1][1]; } } if (dp.back()[0][0] < dp.back()[1][0]) { swap(dp.back()[0], dp.back()[1]); } if (dp.back()[0][1] <= k) { r = md - 1, res = max(res, dp.back()[0][0] + md * dp.back()[0][1]); } else if (dp.back()[0][1] > k){ l = md + 1; } } cout << res; }
#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...