Submission #416450

# Submission time Handle Problem Language Result Execution time Memory
416450 2021-06-02T12:00:45 Z Aldas25 Feast (NOI19_feast) C++14
100 / 100
157 ms 12868 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 300100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 1e13;
const ld PI = asin(1) * 2;
const ld EPS = 1e-6;

ll n, k;
ll a[MAXN];
ll pref[MAXN];
ll dp[MAXN];
ll cnt[MAXN];

void calc (ll lambda) {
    //cout << fixed << setprecision(3) << "    lambda = " << lambda << endl;
    int bg = 0;
    FOR(i, 1, n) {
        if (dp[bg] + pref[i] - pref[bg] - lambda > dp[i-1]) {
            dp[i] = dp[bg] + pref[i] - pref[bg] - lambda;
            cnt[i] = cnt[bg]+1;
        } else {
            dp[i] = dp[i-1];
            cnt[i] = cnt[i-1];
        }

        if (dp[bg] - pref[bg] < dp[i] - pref[i]) {
            bg = i;
        }

       // cout << fixed << setprecision(2) << " i = " << i << " dp = " << dp[i] << " pref = " << pref[i] << "  bg = " << bg << " cnt = " << cnt[i] << endl;
    }
}

int main()
{
    FAST_IO;

    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) pref[i] = pref[i-1] + a[i];

    ll le = 0, ri = INF;
    while (le < ri) {
        ll mid = (le+ri)/2;
        calc (mid);
        if (cnt[n] <= k) ri = mid;
        else le = mid+1;
    }

    calc (le);
    //ll ans = (ll)(round(dp[n] + cnt[n]*le));
    ll ans = dp[n] + cnt[n]*le;
    cout << ans << "\n";

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 110 ms 9996 KB Output is correct
2 Correct 116 ms 12520 KB Output is correct
3 Correct 120 ms 12480 KB Output is correct
4 Correct 117 ms 12608 KB Output is correct
5 Correct 114 ms 12408 KB Output is correct
6 Correct 112 ms 12228 KB Output is correct
7 Correct 115 ms 12324 KB Output is correct
8 Correct 115 ms 12356 KB Output is correct
9 Correct 119 ms 12220 KB Output is correct
10 Correct 115 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 9536 KB Output is correct
2 Correct 109 ms 10744 KB Output is correct
3 Correct 107 ms 10592 KB Output is correct
4 Correct 99 ms 10648 KB Output is correct
5 Correct 117 ms 12352 KB Output is correct
6 Correct 95 ms 10692 KB Output is correct
7 Correct 104 ms 10948 KB Output is correct
8 Correct 114 ms 12420 KB Output is correct
9 Correct 111 ms 12200 KB Output is correct
10 Correct 98 ms 10796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 10308 KB Output is correct
2 Correct 106 ms 12420 KB Output is correct
3 Correct 105 ms 12592 KB Output is correct
4 Correct 106 ms 12480 KB Output is correct
5 Correct 108 ms 12568 KB Output is correct
6 Correct 107 ms 12668 KB Output is correct
7 Correct 110 ms 12700 KB Output is correct
8 Correct 106 ms 12492 KB Output is correct
9 Correct 107 ms 12752 KB Output is correct
10 Correct 105 ms 12644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 9996 KB Output is correct
2 Correct 116 ms 12520 KB Output is correct
3 Correct 120 ms 12480 KB Output is correct
4 Correct 117 ms 12608 KB Output is correct
5 Correct 114 ms 12408 KB Output is correct
6 Correct 112 ms 12228 KB Output is correct
7 Correct 115 ms 12324 KB Output is correct
8 Correct 115 ms 12356 KB Output is correct
9 Correct 119 ms 12220 KB Output is correct
10 Correct 115 ms 12356 KB Output is correct
11 Correct 90 ms 9536 KB Output is correct
12 Correct 109 ms 10744 KB Output is correct
13 Correct 107 ms 10592 KB Output is correct
14 Correct 99 ms 10648 KB Output is correct
15 Correct 117 ms 12352 KB Output is correct
16 Correct 95 ms 10692 KB Output is correct
17 Correct 104 ms 10948 KB Output is correct
18 Correct 114 ms 12420 KB Output is correct
19 Correct 111 ms 12200 KB Output is correct
20 Correct 98 ms 10796 KB Output is correct
21 Correct 103 ms 10308 KB Output is correct
22 Correct 106 ms 12420 KB Output is correct
23 Correct 105 ms 12592 KB Output is correct
24 Correct 106 ms 12480 KB Output is correct
25 Correct 108 ms 12568 KB Output is correct
26 Correct 107 ms 12668 KB Output is correct
27 Correct 110 ms 12700 KB Output is correct
28 Correct 106 ms 12492 KB Output is correct
29 Correct 107 ms 12752 KB Output is correct
30 Correct 105 ms 12644 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 272 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 145 ms 12452 KB Output is correct
62 Correct 157 ms 12868 KB Output is correct
63 Correct 113 ms 12356 KB Output is correct
64 Correct 155 ms 12664 KB Output is correct
65 Correct 141 ms 12592 KB Output is correct
66 Correct 134 ms 12612 KB Output is correct
67 Correct 132 ms 12440 KB Output is correct
68 Correct 105 ms 12632 KB Output is correct
69 Correct 104 ms 12356 KB Output is correct
70 Correct 106 ms 12352 KB Output is correct