답안 #996992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996992 2024-06-11T14:43:23 Z blackslex Feast (NOI19_feast) C++17
100 / 100
113 ms 11612 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

int n, k;

int main() {
    scanf("%d %d", &n, &k);
    vector<ll> a(n + 5), pref(n + 5);
    vector<pii> dp(n + 5);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i];
    auto get = [&] (ll x) {
        pii cmx(0, 0);
        for (int i = 1; i <= n; i++) {
            dp[i] = max(dp[i - 1], {cmx.first + pref[i] - x, cmx.second - 1});
            cmx = max(cmx, {dp[i].first - pref[i], dp[i].second});
        }
        return pii(dp[n].first, -dp[n].second);
    };
    ll l = 0, r = 3e14;
    while (l <= r) {
        ll mid = (l + r) >> 1LL;
        if (get(mid).second <= k) r = mid - 1;
        else l = mid + 1;
    }
    printf("%lld", get(l).first + l * k);
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
feast.cpp:13:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i];
      |                                  ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10844 KB Output is correct
2 Correct 54 ms 11476 KB Output is correct
3 Correct 38 ms 11612 KB Output is correct
4 Correct 40 ms 11472 KB Output is correct
5 Correct 38 ms 11356 KB Output is correct
6 Correct 38 ms 10844 KB Output is correct
7 Correct 39 ms 11060 KB Output is correct
8 Correct 39 ms 11348 KB Output is correct
9 Correct 37 ms 11100 KB Output is correct
10 Correct 41 ms 11348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 10328 KB Output is correct
2 Correct 40 ms 10332 KB Output is correct
3 Correct 38 ms 10328 KB Output is correct
4 Correct 37 ms 10328 KB Output is correct
5 Correct 37 ms 11056 KB Output is correct
6 Correct 36 ms 10332 KB Output is correct
7 Correct 40 ms 10588 KB Output is correct
8 Correct 39 ms 11356 KB Output is correct
9 Correct 40 ms 10844 KB Output is correct
10 Correct 46 ms 10524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 11352 KB Output is correct
2 Correct 66 ms 11324 KB Output is correct
3 Correct 68 ms 11224 KB Output is correct
4 Correct 84 ms 11348 KB Output is correct
5 Correct 78 ms 11348 KB Output is correct
6 Correct 69 ms 11356 KB Output is correct
7 Correct 75 ms 11352 KB Output is correct
8 Correct 66 ms 11436 KB Output is correct
9 Correct 68 ms 11592 KB Output is correct
10 Correct 77 ms 11612 KB Output is correct
# 결과 실행 시간 메모리 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 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 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 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 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 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 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 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 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 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 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 348 KB Output is correct
25 Correct 1 ms 600 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 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10844 KB Output is correct
2 Correct 54 ms 11476 KB Output is correct
3 Correct 38 ms 11612 KB Output is correct
4 Correct 40 ms 11472 KB Output is correct
5 Correct 38 ms 11356 KB Output is correct
6 Correct 38 ms 10844 KB Output is correct
7 Correct 39 ms 11060 KB Output is correct
8 Correct 39 ms 11348 KB Output is correct
9 Correct 37 ms 11100 KB Output is correct
10 Correct 41 ms 11348 KB Output is correct
11 Correct 41 ms 10328 KB Output is correct
12 Correct 40 ms 10332 KB Output is correct
13 Correct 38 ms 10328 KB Output is correct
14 Correct 37 ms 10328 KB Output is correct
15 Correct 37 ms 11056 KB Output is correct
16 Correct 36 ms 10332 KB Output is correct
17 Correct 40 ms 10588 KB Output is correct
18 Correct 39 ms 11356 KB Output is correct
19 Correct 40 ms 10844 KB Output is correct
20 Correct 46 ms 10524 KB Output is correct
21 Correct 67 ms 11352 KB Output is correct
22 Correct 66 ms 11324 KB Output is correct
23 Correct 68 ms 11224 KB Output is correct
24 Correct 84 ms 11348 KB Output is correct
25 Correct 78 ms 11348 KB Output is correct
26 Correct 69 ms 11356 KB Output is correct
27 Correct 75 ms 11352 KB Output is correct
28 Correct 66 ms 11436 KB Output is correct
29 Correct 68 ms 11592 KB Output is correct
30 Correct 77 ms 11612 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 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 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 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 344 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 348 KB Output is correct
55 Correct 1 ms 600 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 348 KB Output is correct
61 Correct 107 ms 11300 KB Output is correct
62 Correct 89 ms 11600 KB Output is correct
63 Correct 76 ms 11348 KB Output is correct
64 Correct 93 ms 11356 KB Output is correct
65 Correct 101 ms 11348 KB Output is correct
66 Correct 113 ms 11296 KB Output is correct
67 Correct 100 ms 11356 KB Output is correct
68 Correct 70 ms 11360 KB Output is correct
69 Correct 66 ms 11344 KB Output is correct
70 Correct 75 ms 11308 KB Output is correct