답안 #1025728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025728 2024-07-17T09:20:02 Z Gr1sen Feast (NOI19_feast) C++17
100 / 100
125 ms 15188 KB
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define ppi pair<ll, pi>
#define vp vector<ppi>
#define vvp vector<vp>
#define MP make_pair

ll n, k;
vi L;

pi oink(ll c) {
    pi dp[n][2];

    dp[0][0] = {0, 0};
    dp[0][1] = {L[0] - c, 1};
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);

        dp[i][1] = max(MP(dp[i-1][1].first + L[i], dp[i-1][1].second), MP(dp[i-1][0].first + L[i] - c, dp[i-1][0].second + 1));
    }
    return max(dp[n-1][0], dp[n-1][1]);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    L = vi(n);
    for (auto &i : L) cin >> i;

    ll l = 0, r = 1e18;
    ll ans = 0;
    while (l < r) {
        //cerr << l << " " << r << endl;
        ll m = (l+r)/2;
        pi a = oink(m);
        if (a.second == k) {
            ans = a.first + m*k;
            break;
        }
        if (a.second > k) {
            l = m+1;
            continue;
        }
        ans = a.first + a.second*m;
        r = m;
    }
    cout << ans << "\n";
}

/*
6 1
1 -2 3 -1 5 -6

6 2
1 2 3 -10 5 6

6 4
-1 -2 -1 0 -5 -1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 11596 KB Output is correct
2 Correct 68 ms 11864 KB Output is correct
3 Correct 86 ms 12124 KB Output is correct
4 Correct 68 ms 11864 KB Output is correct
5 Correct 72 ms 11984 KB Output is correct
6 Correct 75 ms 11700 KB Output is correct
7 Correct 75 ms 11604 KB Output is correct
8 Correct 70 ms 11864 KB Output is correct
9 Correct 67 ms 11868 KB Output is correct
10 Correct 90 ms 11712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 11864 KB Output is correct
2 Correct 44 ms 12024 KB Output is correct
3 Correct 42 ms 11860 KB Output is correct
4 Correct 64 ms 11992 KB Output is correct
5 Correct 35 ms 11708 KB Output is correct
6 Correct 47 ms 11868 KB Output is correct
7 Correct 63 ms 12124 KB Output is correct
8 Correct 34 ms 11868 KB Output is correct
9 Correct 34 ms 11604 KB Output is correct
10 Correct 63 ms 11868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 11868 KB Output is correct
2 Correct 67 ms 11864 KB Output is correct
3 Correct 58 ms 11868 KB Output is correct
4 Correct 61 ms 11720 KB Output is correct
5 Correct 64 ms 11860 KB Output is correct
6 Correct 58 ms 11860 KB Output is correct
7 Correct 62 ms 12020 KB Output is correct
8 Correct 58 ms 11868 KB Output is correct
9 Correct 58 ms 12112 KB Output is correct
10 Correct 56 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 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 0 ms 348 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 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 0 ms 348 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 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 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 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 11596 KB Output is correct
2 Correct 68 ms 11864 KB Output is correct
3 Correct 86 ms 12124 KB Output is correct
4 Correct 68 ms 11864 KB Output is correct
5 Correct 72 ms 11984 KB Output is correct
6 Correct 75 ms 11700 KB Output is correct
7 Correct 75 ms 11604 KB Output is correct
8 Correct 70 ms 11864 KB Output is correct
9 Correct 67 ms 11868 KB Output is correct
10 Correct 90 ms 11712 KB Output is correct
11 Correct 43 ms 11864 KB Output is correct
12 Correct 44 ms 12024 KB Output is correct
13 Correct 42 ms 11860 KB Output is correct
14 Correct 64 ms 11992 KB Output is correct
15 Correct 35 ms 11708 KB Output is correct
16 Correct 47 ms 11868 KB Output is correct
17 Correct 63 ms 12124 KB Output is correct
18 Correct 34 ms 11868 KB Output is correct
19 Correct 34 ms 11604 KB Output is correct
20 Correct 63 ms 11868 KB Output is correct
21 Correct 60 ms 11868 KB Output is correct
22 Correct 67 ms 11864 KB Output is correct
23 Correct 58 ms 11868 KB Output is correct
24 Correct 61 ms 11720 KB Output is correct
25 Correct 64 ms 11860 KB Output is correct
26 Correct 58 ms 11860 KB Output is correct
27 Correct 62 ms 12020 KB Output is correct
28 Correct 58 ms 11868 KB Output is correct
29 Correct 58 ms 12112 KB Output is correct
30 Correct 56 ms 12108 KB Output is correct
31 Correct 1 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 1 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 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 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 0 ms 348 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 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 344 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 0 ms 348 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 97 ms 11704 KB Output is correct
62 Correct 125 ms 15188 KB Output is correct
63 Correct 86 ms 14676 KB Output is correct
64 Correct 115 ms 14924 KB Output is correct
65 Correct 97 ms 14932 KB Output is correct
66 Correct 101 ms 14932 KB Output is correct
67 Correct 94 ms 14776 KB Output is correct
68 Correct 72 ms 14932 KB Output is correct
69 Correct 73 ms 14760 KB Output is correct
70 Correct 56 ms 14628 KB Output is correct