Submission #1078191

#TimeUsernameProblemLanguageResultExecution timeMemory
1078191South_CloudFeast (NOI19_feast)C++17
100 / 100
121 ms14060 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; const int N = 3e5 + 7; int n, k, a[N]; void input() { cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; } } pair<long long, int> dp[N][2]; pair<long long, long long> solveLambda(long long x) { dp[1][0] = make_pair(0, 0); dp[1][1] = make_pair(a[1] - x, 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].fi + a[i] - x, dp[i - 1][0].se + 1), make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se)); } return max(dp[n][0], dp[n][1]); } void solve() { long long l = 0, r = 1e18; while(r - l > 1) { long long mid = (l + r) >> 1; pair<long long, long long> cur = solveLambda(mid); if(cur.se >= k) l = mid; else r = mid; } cout << solveLambda(l).fi + l * k; } int main() { cin.tie(NULL)->ios_base::sync_with_stdio(NULL); //freopen(" .inp", "r", stdin); //freopen(" .out", "w", stdout); input(); solve(); 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...