Submission #1017315

# Submission time Handle Problem Language Result Execution time Memory
1017315 2024-07-09T07:22:17 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
131 ms 12368 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define aint(v) v.begin(), v.end()
using namespace std;

const int N=3e5+5, mod = 1e9+7, inf = 1e18;

int n, k;
int a[N];
ii dp[N][2];

ii check(int t) {
    dp[0][0] = {0, 0};
    dp[0][1] = {a[0] - t, 1};

    for (int i = 1; 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] - t, dp[i - 1][0].se + 1), make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se));
    }

    return max(dp[n - 1][0], dp[n - 1][1]);
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i=0; i<n; i++) cin >> a[i];

    int lo = 0;
    int hi = 1e18;
    while (lo < hi) {
        int mid = (lo + hi + 1) / 2;
        check(mid).se >= k ? lo = mid : hi = mid - 1;
    }

    cout << check(lo).first + lo * k;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 12124 KB Output is correct
2 Correct 55 ms 12120 KB Output is correct
3 Correct 63 ms 11980 KB Output is correct
4 Correct 53 ms 12120 KB Output is correct
5 Correct 54 ms 12112 KB Output is correct
6 Correct 53 ms 11984 KB Output is correct
7 Correct 52 ms 11860 KB Output is correct
8 Correct 54 ms 12120 KB Output is correct
9 Correct 54 ms 12068 KB Output is correct
10 Correct 53 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11984 KB Output is correct
2 Correct 65 ms 12124 KB Output is correct
3 Correct 50 ms 12124 KB Output is correct
4 Correct 46 ms 12144 KB Output is correct
5 Correct 57 ms 11860 KB Output is correct
6 Correct 49 ms 12124 KB Output is correct
7 Correct 48 ms 12120 KB Output is correct
8 Correct 56 ms 12124 KB Output is correct
9 Correct 54 ms 11856 KB Output is correct
10 Correct 49 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 12120 KB Output is correct
2 Correct 83 ms 12116 KB Output is correct
3 Correct 81 ms 12368 KB Output is correct
4 Correct 80 ms 12128 KB Output is correct
5 Correct 79 ms 12116 KB Output is correct
6 Correct 82 ms 12120 KB Output is correct
7 Correct 90 ms 12116 KB Output is correct
8 Correct 79 ms 12124 KB Output is correct
9 Correct 81 ms 12124 KB Output is correct
10 Correct 99 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2476 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 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 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 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 12124 KB Output is correct
2 Correct 55 ms 12120 KB Output is correct
3 Correct 63 ms 11980 KB Output is correct
4 Correct 53 ms 12120 KB Output is correct
5 Correct 54 ms 12112 KB Output is correct
6 Correct 53 ms 11984 KB Output is correct
7 Correct 52 ms 11860 KB Output is correct
8 Correct 54 ms 12120 KB Output is correct
9 Correct 54 ms 12068 KB Output is correct
10 Correct 53 ms 12124 KB Output is correct
11 Correct 48 ms 11984 KB Output is correct
12 Correct 65 ms 12124 KB Output is correct
13 Correct 50 ms 12124 KB Output is correct
14 Correct 46 ms 12144 KB Output is correct
15 Correct 57 ms 11860 KB Output is correct
16 Correct 49 ms 12124 KB Output is correct
17 Correct 48 ms 12120 KB Output is correct
18 Correct 56 ms 12124 KB Output is correct
19 Correct 54 ms 11856 KB Output is correct
20 Correct 49 ms 12124 KB Output is correct
21 Correct 82 ms 12120 KB Output is correct
22 Correct 83 ms 12116 KB Output is correct
23 Correct 81 ms 12368 KB Output is correct
24 Correct 80 ms 12128 KB Output is correct
25 Correct 79 ms 12116 KB Output is correct
26 Correct 82 ms 12120 KB Output is correct
27 Correct 90 ms 12116 KB Output is correct
28 Correct 79 ms 12124 KB Output is correct
29 Correct 81 ms 12124 KB Output is correct
30 Correct 99 ms 12112 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 2476 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 2 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 344 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 2396 KB Output is correct
61 Correct 114 ms 12096 KB Output is correct
62 Correct 131 ms 12024 KB Output is correct
63 Correct 127 ms 11856 KB Output is correct
64 Correct 114 ms 12156 KB Output is correct
65 Correct 116 ms 12096 KB Output is correct
66 Correct 117 ms 12148 KB Output is correct
67 Correct 118 ms 12124 KB Output is correct
68 Correct 84 ms 12160 KB Output is correct
69 Correct 79 ms 12116 KB Output is correct
70 Correct 80 ms 12120 KB Output is correct