Submission #1078191

# Submission time Handle Problem Language Result Execution time Memory
1078191 2024-08-27T13:47:59 Z South_Cloud Feast (NOI19_feast) C++17
100 / 100
121 ms 14060 KB
	#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

const int N = 3e5 + 7;

int n, k, a[N];

void input() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
}

pair<long long, int> dp[N][2];

pair<long long, long long> solveLambda(long long x) {
    dp[1][0] = make_pair(0, 0);
    dp[1][1] = make_pair(a[1] - x, 1);
    for(int i = 2; i <= n; i++) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = max(make_pair(dp[i - 1][0].fi + a[i] - x, dp[i - 1][0].se + 1),
                       make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se));
    }
    return max(dp[n][0], dp[n][1]);
}

void solve() {
    long long l = 0, r = 1e18;
    while(r - l > 1) {
        long long mid = (l + r) >> 1;
        pair<long long, long long> cur = solveLambda(mid);
        if(cur.se >= k) l = mid;
            else r = mid;
    }
    cout << solveLambda(l).fi + l * k;
}

int main() {
    cin.tie(NULL)->ios_base::sync_with_stdio(NULL);
    //freopen(" .inp", "r", stdin);
    //freopen(" .out", "w", stdout);
    input();
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 52 ms 13392 KB Output is correct
2 Correct 55 ms 13728 KB Output is correct
3 Correct 55 ms 13872 KB Output is correct
4 Correct 55 ms 13780 KB Output is correct
5 Correct 53 ms 13648 KB Output is correct
6 Correct 56 ms 13452 KB Output is correct
7 Correct 53 ms 13392 KB Output is correct
8 Correct 57 ms 13652 KB Output is correct
9 Correct 54 ms 13392 KB Output is correct
10 Correct 52 ms 13392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 11864 KB Output is correct
2 Correct 46 ms 12120 KB Output is correct
3 Correct 44 ms 11868 KB Output is correct
4 Correct 45 ms 11868 KB Output is correct
5 Correct 56 ms 13380 KB Output is correct
6 Correct 47 ms 11608 KB Output is correct
7 Correct 49 ms 12012 KB Output is correct
8 Correct 54 ms 13648 KB Output is correct
9 Correct 51 ms 13648 KB Output is correct
10 Correct 45 ms 11868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 13908 KB Output is correct
2 Correct 81 ms 13728 KB Output is correct
3 Correct 82 ms 13876 KB Output is correct
4 Correct 97 ms 13748 KB Output is correct
5 Correct 88 ms 13648 KB Output is correct
6 Correct 80 ms 13744 KB Output is correct
7 Correct 83 ms 13908 KB Output is correct
8 Correct 87 ms 13652 KB Output is correct
9 Correct 85 ms 14044 KB Output is correct
10 Correct 83 ms 13964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 1 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 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 564 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 480 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 13392 KB Output is correct
2 Correct 55 ms 13728 KB Output is correct
3 Correct 55 ms 13872 KB Output is correct
4 Correct 55 ms 13780 KB Output is correct
5 Correct 53 ms 13648 KB Output is correct
6 Correct 56 ms 13452 KB Output is correct
7 Correct 53 ms 13392 KB Output is correct
8 Correct 57 ms 13652 KB Output is correct
9 Correct 54 ms 13392 KB Output is correct
10 Correct 52 ms 13392 KB Output is correct
11 Correct 47 ms 11864 KB Output is correct
12 Correct 46 ms 12120 KB Output is correct
13 Correct 44 ms 11868 KB Output is correct
14 Correct 45 ms 11868 KB Output is correct
15 Correct 56 ms 13380 KB Output is correct
16 Correct 47 ms 11608 KB Output is correct
17 Correct 49 ms 12012 KB Output is correct
18 Correct 54 ms 13648 KB Output is correct
19 Correct 51 ms 13648 KB Output is correct
20 Correct 45 ms 11868 KB Output is correct
21 Correct 80 ms 13908 KB Output is correct
22 Correct 81 ms 13728 KB Output is correct
23 Correct 82 ms 13876 KB Output is correct
24 Correct 97 ms 13748 KB Output is correct
25 Correct 88 ms 13648 KB Output is correct
26 Correct 80 ms 13744 KB Output is correct
27 Correct 83 ms 13908 KB Output is correct
28 Correct 87 ms 13652 KB Output is correct
29 Correct 85 ms 14044 KB Output is correct
30 Correct 83 ms 13964 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 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 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 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 564 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 480 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 117 ms 13908 KB Output is correct
62 Correct 117 ms 14060 KB Output is correct
63 Correct 96 ms 13600 KB Output is correct
64 Correct 120 ms 13904 KB Output is correct
65 Correct 121 ms 13904 KB Output is correct
66 Correct 121 ms 13900 KB Output is correct
67 Correct 118 ms 13632 KB Output is correct
68 Correct 81 ms 13908 KB Output is correct
69 Correct 86 ms 13648 KB Output is correct
70 Correct 80 ms 13648 KB Output is correct