Submission #939713

#TimeUsernameProblemLanguageResultExecution timeMemory
939713TrinhKhanhDungFeast (NOI19_feast)C++14
0 / 100
183 ms23124 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 10; const long double EPS = 1e-3; int N, K; int a[MAX]; pair<long double, int> dp[MAX][2]; bool OK(long double lambda){ dp[0][0] = make_pair(0.0, 0); dp[0][1] = make_pair(-1.18, 0); 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][1].first + a[i], dp[i - 1][1].second), make_pair(dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1)); } return max(dp[N][0].second, dp[N][1].second) >= K; } int main(){ ios_base::sync_with_stdio(0); cin >> N >> K; for(int i=1; i<=N; i++){ cin >> a[i]; } long double lo = 0, hi = 1e14; while(lo + EPS < hi){ long double mid = (lo + hi) / 2; if(OK(mid)){ lo = mid; } else{ hi = mid; } } OK(lo); cout << round(lo * K + max(dp[N][0], dp[N][1]).first); 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...