Submission #1026013

# Submission time Handle Problem Language Result Execution time Memory
1026013 2024-07-17T12:35:18 Z ach00 Feast (NOI19_feast) C++14
100 / 100
93 ms 5460 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define EPS 0.00001
int n,k;
vector<ll> W;
pair<ll,ll> solve(ll pen) {
    pair<ll,ll> zero = {0,0};
    pair<ll,ll> one = {W[0] - pen, 1};
    for(int i = 1; i < n; i++) {
        pair<ll,ll> _zero, _one;
        _zero = max(zero, one);
        _one = max(MP(one.first + W[i], one.second), MP(zero.first + W[i] - pen, zero.second + 1));
        zero = _zero;
        one = _one;
    }
    return max(zero, one);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    ll lower = 0;
    ll upper = 10000000000000;
    W.resize(n); for(auto &a : W) cin >> a;
    while(lower < upper) {
        ll m = (lower+upper+1)/2;
        auto K = solve(m);
        if(K.second >= k) {
            lower = m;
        } else {
            upper = m-1;
        }
    }
    auto K = solve(lower);
    cout << K.first + k*lower;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 4396 KB Output is correct
2 Correct 39 ms 4432 KB Output is correct
3 Correct 39 ms 4420 KB Output is correct
4 Correct 38 ms 4440 KB Output is correct
5 Correct 39 ms 4432 KB Output is correct
6 Correct 38 ms 4308 KB Output is correct
7 Correct 42 ms 4340 KB Output is correct
8 Correct 38 ms 4436 KB Output is correct
9 Correct 38 ms 4440 KB Output is correct
10 Correct 38 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3416 KB Output is correct
2 Correct 31 ms 3420 KB Output is correct
3 Correct 35 ms 3444 KB Output is correct
4 Correct 32 ms 3416 KB Output is correct
5 Correct 38 ms 4432 KB Output is correct
6 Correct 30 ms 3420 KB Output is correct
7 Correct 31 ms 3420 KB Output is correct
8 Correct 38 ms 4440 KB Output is correct
9 Correct 38 ms 4236 KB Output is correct
10 Correct 31 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 5456 KB Output is correct
2 Correct 58 ms 5120 KB Output is correct
3 Correct 54 ms 5208 KB Output is correct
4 Correct 63 ms 5400 KB Output is correct
5 Correct 54 ms 5204 KB Output is correct
6 Correct 58 ms 5200 KB Output is correct
7 Correct 55 ms 5140 KB Output is correct
8 Correct 55 ms 5204 KB Output is correct
9 Correct 58 ms 5212 KB Output is correct
10 Correct 58 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 472 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 4396 KB Output is correct
2 Correct 39 ms 4432 KB Output is correct
3 Correct 39 ms 4420 KB Output is correct
4 Correct 38 ms 4440 KB Output is correct
5 Correct 39 ms 4432 KB Output is correct
6 Correct 38 ms 4308 KB Output is correct
7 Correct 42 ms 4340 KB Output is correct
8 Correct 38 ms 4436 KB Output is correct
9 Correct 38 ms 4440 KB Output is correct
10 Correct 38 ms 4432 KB Output is correct
11 Correct 30 ms 3416 KB Output is correct
12 Correct 31 ms 3420 KB Output is correct
13 Correct 35 ms 3444 KB Output is correct
14 Correct 32 ms 3416 KB Output is correct
15 Correct 38 ms 4432 KB Output is correct
16 Correct 30 ms 3420 KB Output is correct
17 Correct 31 ms 3420 KB Output is correct
18 Correct 38 ms 4440 KB Output is correct
19 Correct 38 ms 4236 KB Output is correct
20 Correct 31 ms 3932 KB Output is correct
21 Correct 55 ms 5456 KB Output is correct
22 Correct 58 ms 5120 KB Output is correct
23 Correct 54 ms 5208 KB Output is correct
24 Correct 63 ms 5400 KB Output is correct
25 Correct 54 ms 5204 KB Output is correct
26 Correct 58 ms 5200 KB Output is correct
27 Correct 55 ms 5140 KB Output is correct
28 Correct 55 ms 5204 KB Output is correct
29 Correct 58 ms 5212 KB Output is correct
30 Correct 58 ms 5200 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 376 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 472 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 87 ms 5104 KB Output is correct
62 Correct 80 ms 5212 KB Output is correct
63 Correct 68 ms 5204 KB Output is correct
64 Correct 85 ms 5212 KB Output is correct
65 Correct 90 ms 5216 KB Output is correct
66 Correct 93 ms 5292 KB Output is correct
67 Correct 91 ms 5208 KB Output is correct
68 Correct 56 ms 5200 KB Output is correct
69 Correct 56 ms 5116 KB Output is correct
70 Correct 57 ms 5460 KB Output is correct