Submission #778852

# Submission time Handle Problem Language Result Execution time Memory
778852 2023-07-10T20:53:22 Z doowey Feast (NOI19_feast) C++14
100 / 100
130 ms 10412 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)3e5 + 10;
const ll inf = (ll)1e18;
ll P[N];

pii dp[N];
int n;

void compute(ll penalty){
    for(int i = 1 ; i <= n; i ++ ){
        dp[i]=mp(-inf,0);
    }
    pii cur=mp(dp[0].fi-P[0]-penalty, 1);
    for(int i = 1; i <= n; i ++ ){
        dp[i]=max(dp[i-1],mp(cur.fi+P[i],cur.se));
        cur=max(cur,mp(dp[i].fi-P[i]-penalty,dp[i].se+1));
    }
}

int main(){
    fastIO;
    int k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++ ){
        cin >> P[i];
        P[i]+=P[i-1];
    }
    ll lf = 0ll;
    ll rf = (ll)1e18;
    ll mid;
    ll penalty;

    while(lf < rf){
        mid = (lf + rf) / 2;
        compute(mid);
        if(dp[n].se > k){
            lf=mid+1;
        }
        else{
            rf=mid;
        }
    }
    compute(lf);
    cout << dp[n].fi + dp[n].se * 1ll * lf << "\n";
    return 0;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:42:8: warning: unused variable 'penalty' [-Wunused-variable]
   42 |     ll penalty;
      |        ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 7124 KB Output is correct
2 Correct 87 ms 10120 KB Output is correct
3 Correct 89 ms 10188 KB Output is correct
4 Correct 87 ms 10168 KB Output is correct
5 Correct 85 ms 10096 KB Output is correct
6 Correct 85 ms 9984 KB Output is correct
7 Correct 84 ms 9936 KB Output is correct
8 Correct 86 ms 10060 KB Output is correct
9 Correct 85 ms 9944 KB Output is correct
10 Correct 85 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 7260 KB Output is correct
2 Correct 72 ms 7292 KB Output is correct
3 Correct 73 ms 7172 KB Output is correct
4 Correct 74 ms 7192 KB Output is correct
5 Correct 84 ms 9932 KB Output is correct
6 Correct 71 ms 8196 KB Output is correct
7 Correct 77 ms 8496 KB Output is correct
8 Correct 86 ms 10188 KB Output is correct
9 Correct 85 ms 9876 KB Output is correct
10 Correct 77 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 7272 KB Output is correct
2 Correct 97 ms 7184 KB Output is correct
3 Correct 97 ms 7248 KB Output is correct
4 Correct 94 ms 7192 KB Output is correct
5 Correct 93 ms 7248 KB Output is correct
6 Correct 97 ms 7200 KB Output is correct
7 Correct 102 ms 7316 KB Output is correct
8 Correct 94 ms 7248 KB Output is correct
9 Correct 96 ms 7252 KB Output is correct
10 Correct 95 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 7124 KB Output is correct
2 Correct 87 ms 10120 KB Output is correct
3 Correct 89 ms 10188 KB Output is correct
4 Correct 87 ms 10168 KB Output is correct
5 Correct 85 ms 10096 KB Output is correct
6 Correct 85 ms 9984 KB Output is correct
7 Correct 84 ms 9936 KB Output is correct
8 Correct 86 ms 10060 KB Output is correct
9 Correct 85 ms 9944 KB Output is correct
10 Correct 85 ms 10060 KB Output is correct
11 Correct 71 ms 7260 KB Output is correct
12 Correct 72 ms 7292 KB Output is correct
13 Correct 73 ms 7172 KB Output is correct
14 Correct 74 ms 7192 KB Output is correct
15 Correct 84 ms 9932 KB Output is correct
16 Correct 71 ms 8196 KB Output is correct
17 Correct 77 ms 8496 KB Output is correct
18 Correct 86 ms 10188 KB Output is correct
19 Correct 85 ms 9876 KB Output is correct
20 Correct 77 ms 8440 KB Output is correct
21 Correct 105 ms 7272 KB Output is correct
22 Correct 97 ms 7184 KB Output is correct
23 Correct 97 ms 7248 KB Output is correct
24 Correct 94 ms 7192 KB Output is correct
25 Correct 93 ms 7248 KB Output is correct
26 Correct 97 ms 7200 KB Output is correct
27 Correct 102 ms 7316 KB Output is correct
28 Correct 94 ms 7248 KB Output is correct
29 Correct 96 ms 7252 KB Output is correct
30 Correct 95 ms 7252 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 124 ms 10160 KB Output is correct
62 Correct 126 ms 10412 KB Output is correct
63 Correct 120 ms 10136 KB Output is correct
64 Correct 128 ms 10248 KB Output is correct
65 Correct 130 ms 10316 KB Output is correct
66 Correct 127 ms 10188 KB Output is correct
67 Correct 127 ms 10148 KB Output is correct
68 Correct 106 ms 10340 KB Output is correct
69 Correct 93 ms 10152 KB Output is correct
70 Correct 94 ms 10100 KB Output is correct