Submission #545010

#TimeUsernameProblemLanguageResultExecution timeMemory
545010pure_memFeast (NOI19_feast)C++14
100 / 100
705 ms24588 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define X first #define Y second #define MP make_pair using namespace std; const int N = 3e5 + 12; int n, k; ll a[N]; pair<ld, int> dp[N][2]; void prints(pair<ld, int> x) { cerr << x.X << " " << x.Y; } pair<ld, int> get(ld m, bool debug = 0) { dp[1][0] = {0, 0}; dp[1][1] = {a[1] - m, 1}; for(int i = 2;i <= n;i++) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(MP(dp[i - 1][0].X + a[i] - m, dp[i - 1][0].Y + 1), MP(dp[i - 1][1].X + a[i], dp[i - 1][1].Y)); if(debug) { prints(dp[i][0]), cerr << " | ", prints(dp[i][1]); cerr << "\n"; } } return max(dp[n][0], dp[n][1]); } int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1;i <= n;i++) cin >> a[i]; ld l = 0, r = 1e15; for(int it = 0;it < 100;it++) { ld m = (l + r) / 2; auto mid = get(m); if(mid.Y >= k) { l = m; } else { r = m; } } auto mid = get(l); ll answer = round(mid.X + l * k); cout << answer; }
#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...