Submission #997175

# Submission time Handle Problem Language Result Execution time Memory
997175 2024-06-11T19:09:01 Z anonymous321 Feast (NOI19_feast) C++17
12 / 100
179 ms 11744 KB
// https://oj.uz/problem/view/NOI19_feast
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a (n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    ll ans = 0;
    ll lo = 0;
    ll hi = 1e9;
    while (lo < hi) {
        ll mid = lo + (hi - lo)/2;
        vector<ll> dp (n+1, 0);
        vector<ll> p (n+1, 0);
        ll best = 0;
        int id = 0;
        vector<int> cnt (n+1, 0);
        for (int i = 0; i < n; i++) {
            p[i+1] = p[i] + a[i];
            dp[i+1] = dp[i];
            cnt[i+1] = cnt[i];
            if (dp[i+1] < best + p[i+1] - mid) {
                dp[i+1] = best + p[i+1] - mid;
                cnt[i+1] = cnt[id] + 1;
            }
            if (best < dp[i+1] - p[i+1]) {
                best = dp[i+1] - p[i+1];
                id = i+1;
            }
        }
        
        if (cnt[n] <= k) {
            hi = mid;
            ans = dp[n];
        } else {
            lo = mid+1;
        }
    }
    cout << ans + k*hi << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 132 ms 8484 KB Output is correct
2 Correct 179 ms 11628 KB Output is correct
3 Correct 138 ms 11620 KB Output is correct
4 Correct 136 ms 11532 KB Output is correct
5 Correct 143 ms 11744 KB Output is correct
6 Correct 134 ms 11316 KB Output is correct
7 Correct 141 ms 11324 KB Output is correct
8 Correct 136 ms 11480 KB Output is correct
9 Correct 139 ms 11288 KB Output is correct
10 Correct 134 ms 11492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 8656 KB Output is correct
2 Correct 97 ms 9900 KB Output is correct
3 Correct 85 ms 9652 KB Output is correct
4 Correct 131 ms 9660 KB Output is correct
5 Correct 129 ms 11292 KB Output is correct
6 Correct 106 ms 9616 KB Output is correct
7 Correct 97 ms 9904 KB Output is correct
8 Correct 162 ms 11628 KB Output is correct
9 Correct 130 ms 11324 KB Output is correct
10 Correct 104 ms 9776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 8636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 132 ms 8484 KB Output is correct
2 Correct 179 ms 11628 KB Output is correct
3 Correct 138 ms 11620 KB Output is correct
4 Correct 136 ms 11532 KB Output is correct
5 Correct 143 ms 11744 KB Output is correct
6 Correct 134 ms 11316 KB Output is correct
7 Correct 141 ms 11324 KB Output is correct
8 Correct 136 ms 11480 KB Output is correct
9 Correct 139 ms 11288 KB Output is correct
10 Correct 134 ms 11492 KB Output is correct
11 Correct 78 ms 8656 KB Output is correct
12 Correct 97 ms 9900 KB Output is correct
13 Correct 85 ms 9652 KB Output is correct
14 Correct 131 ms 9660 KB Output is correct
15 Correct 129 ms 11292 KB Output is correct
16 Correct 106 ms 9616 KB Output is correct
17 Correct 97 ms 9904 KB Output is correct
18 Correct 162 ms 11628 KB Output is correct
19 Correct 130 ms 11324 KB Output is correct
20 Correct 104 ms 9776 KB Output is correct
21 Incorrect 167 ms 8636 KB Output isn't correct
22 Halted 0 ms 0 KB -