57892023-09-30 16:05:11zsomborMajomházcpp17Wrong answer 10/100141ms11088 KiB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int n, k;
vector <ll> a(1e5 + 1, 0);
vector <ll> p(1e5 + 1, 0);
vector <ll> dp(1e5 + 1, 0);
vector <ll> cnt(1e5 + 1, -1);

ll sum(int l, int r) {
    return p[r] - p[l - 1];
}

pair <ll, ll> do_dp(ll lam) {
    dp[0] = -lam;
    int last = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = 1e18;
        for (int j = last; j < i; j++) {
            ll cur = dp[j] + lam + sum(j + 1, i) * (i - j);
            if (cur > dp[i]) break;
            dp[i] = cur;
            cnt[i] = cnt[j] + 1;
            last = j;
        }
    }
    return {cnt[n], dp[n]};
}

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
    }
    ll l = 0, r = 1e18, m;
    while (r - l > 1) {
        m = (l + r) / 2;
        (do_dp(m).first >= k ? l = m : r = m);
    }
    cout << do_dp(l).second - k * l;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms7900 KiB
2Wrong answer9ms8176 KiB
subtask210/10
3Accepted4ms8472 KiB
4Accepted4ms8660 KiB
5Accepted4ms8872 KiB
6Accepted4ms8812 KiB
7Accepted4ms9068 KiB
subtask30/10
8Accepted6ms9160 KiB
9Wrong answer4ms9116 KiB
10Wrong answer6ms9372 KiB
11Wrong answer6ms9692 KiB
12Wrong answer4ms9968 KiB
subtask40/20
13Wrong answer8ms9720 KiB
14Wrong answer10ms9668 KiB
15Wrong answer10ms9668 KiB
16Wrong answer12ms9700 KiB
17Wrong answer12ms9724 KiB
18Wrong answer10ms9692 KiB
subtask50/29
19Wrong answer57ms9948 KiB
20Wrong answer61ms9868 KiB
21Wrong answer68ms10000 KiB
22Wrong answer71ms10292 KiB
23Wrong answer72ms10236 KiB
subtask60/31
24Accepted71ms10416 KiB
25Accepted75ms10168 KiB
26Wrong answer92ms10172 KiB
27Wrong answer98ms10136 KiB
28Wrong answer103ms10388 KiB
29Wrong answer108ms10656 KiB
30Wrong answer114ms10596 KiB
31Wrong answer125ms10632 KiB
32Wrong answer130ms10920 KiB
33Wrong answer131ms10852 KiB
34Wrong answer134ms10724 KiB
35Wrong answer141ms10728 KiB
36Wrong answer138ms10760 KiB
37Wrong answer136ms11020 KiB
38Wrong answer140ms11052 KiB
39Wrong answer133ms11088 KiB
40Wrong answer118ms10976 KiB