# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017356 | 2024-07-09T07:33:04 Z | vjudge1 | Feast (NOI19_feast) | C++17 | 57 ms | 11984 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*val.second; 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 | 57 ms | 11560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 11880 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 11984 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 57 ms | 11560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |