# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017361 | 2024-07-09T07:34:33 Z | vjudge1 | Feast (NOI19_feast) | C++17 | 52 ms | 12072 KB |
#include<bits/stdc++.h> using namespace std; #define int long long pair<int, int> dp[300005][2]; int n, k, a[300005]; pair<int, int> sigma(int cost) { for (int i = 1; i <= n; i++) { dp[i][0] = max(dp[i-1][0], dp[i-1][1]); pair<int,int> v1 = {dp[i-1][1].first+a[i],dp[i-1][1].second}; pair<int,int> v2 = {dp[i-1][0].first+a[i]-cost, dp[i-1][0].second+1}; dp[i][1] = (v1.first > v2.first ? v1 : v2); } return max(dp[n][0], dp[n][1]); } void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 0, r = 3e14, mid, ans; while(l <= r) { mid = (l + r) / 2; pair<int, int> val = sigma(mid); if(val.second <= k) { if(val.second == k) { ans=val.first+k*mid; cout << ans; return; } r = mid-1; } else l = mid+1; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("input.inp","r")){ freopen("input.inp", "r", stdin); freopen("output.out", "w", stdout); } int t = 1; // cin >> t; while(t--) { solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 52 ms | 11868 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 26 ms | 11868 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 39 ms | 12072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 52 ms | 11868 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |