답안 #938941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938941 2024-03-06T00:33:59 Z Lilypad Feast (NOI19_feast) C++14
100 / 100
206 ms 12876 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pii pair<ll,ll>
#define fi first
#define se second

const int MAXN= 3e5+5;

int N, K, A[MAXN], op;
pii dp[MAXN];
ll pref[MAXN];

// A : ambil K gratis
// B : ambil berapapun bayar

ll f(ll cost) {
    pii m;
    for (int i=1;i<=N;i++) {
        dp[i] = max(dp[i-1], {m.fi+pref[i]-cost,m.se-1});
        m = max(m,{dp[i].fi-pref[i],dp[i].se});
    }
    op = -dp[N].se;
    return dp[N].fi;
}

signed main() {
    cin>>N>>K;
    for (int i=1;i<=N;i++) {
        cin>>A[i];
        pref[i] = pref[i-1] + A[i];
    }
    ll L=0, R=1e15, mid, res;
    while (L<=R) {
        mid=(L+R)/2;
        f(mid);
        if (op <= K) {
            res = mid;
            R = mid-1;
        }
        else {
            L = mid+1;
        }
    }
    cout<<f(res)+res*K<<endl;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:46:21: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     cout<<f(res)+res*K<<endl;
      |                  ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 12368 KB Output is correct
2 Correct 104 ms 12492 KB Output is correct
3 Correct 102 ms 12496 KB Output is correct
4 Correct 117 ms 12488 KB Output is correct
5 Correct 103 ms 12420 KB Output is correct
6 Correct 111 ms 12512 KB Output is correct
7 Correct 106 ms 12528 KB Output is correct
8 Correct 105 ms 12628 KB Output is correct
9 Correct 103 ms 12372 KB Output is correct
10 Correct 106 ms 12620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10832 KB Output is correct
2 Correct 80 ms 10956 KB Output is correct
3 Correct 76 ms 10852 KB Output is correct
4 Correct 73 ms 10852 KB Output is correct
5 Correct 102 ms 12536 KB Output is correct
6 Correct 68 ms 10848 KB Output is correct
7 Correct 74 ms 10832 KB Output is correct
8 Correct 106 ms 12624 KB Output is correct
9 Correct 100 ms 12380 KB Output is correct
10 Correct 77 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 12656 KB Output is correct
2 Correct 136 ms 12740 KB Output is correct
3 Correct 135 ms 12628 KB Output is correct
4 Correct 136 ms 12644 KB Output is correct
5 Correct 145 ms 12624 KB Output is correct
6 Correct 136 ms 12824 KB Output is correct
7 Correct 136 ms 12844 KB Output is correct
8 Correct 134 ms 12620 KB Output is correct
9 Correct 150 ms 12848 KB Output is correct
10 Correct 136 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2496 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 12368 KB Output is correct
2 Correct 104 ms 12492 KB Output is correct
3 Correct 102 ms 12496 KB Output is correct
4 Correct 117 ms 12488 KB Output is correct
5 Correct 103 ms 12420 KB Output is correct
6 Correct 111 ms 12512 KB Output is correct
7 Correct 106 ms 12528 KB Output is correct
8 Correct 105 ms 12628 KB Output is correct
9 Correct 103 ms 12372 KB Output is correct
10 Correct 106 ms 12620 KB Output is correct
11 Correct 74 ms 10832 KB Output is correct
12 Correct 80 ms 10956 KB Output is correct
13 Correct 76 ms 10852 KB Output is correct
14 Correct 73 ms 10852 KB Output is correct
15 Correct 102 ms 12536 KB Output is correct
16 Correct 68 ms 10848 KB Output is correct
17 Correct 74 ms 10832 KB Output is correct
18 Correct 106 ms 12624 KB Output is correct
19 Correct 100 ms 12380 KB Output is correct
20 Correct 77 ms 10832 KB Output is correct
21 Correct 137 ms 12656 KB Output is correct
22 Correct 136 ms 12740 KB Output is correct
23 Correct 135 ms 12628 KB Output is correct
24 Correct 136 ms 12644 KB Output is correct
25 Correct 145 ms 12624 KB Output is correct
26 Correct 136 ms 12824 KB Output is correct
27 Correct 136 ms 12844 KB Output is correct
28 Correct 134 ms 12620 KB Output is correct
29 Correct 150 ms 12848 KB Output is correct
30 Correct 136 ms 12624 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2496 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 2 ms 2396 KB Output is correct
56 Correct 1 ms 2392 KB Output is correct
57 Correct 2 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 2 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 163 ms 12620 KB Output is correct
62 Correct 182 ms 12648 KB Output is correct
63 Correct 146 ms 12624 KB Output is correct
64 Correct 171 ms 12784 KB Output is correct
65 Correct 206 ms 12764 KB Output is correct
66 Correct 166 ms 12624 KB Output is correct
67 Correct 165 ms 12724 KB Output is correct
68 Correct 161 ms 12876 KB Output is correct
69 Correct 132 ms 12728 KB Output is correct
70 Correct 134 ms 12696 KB Output is correct