Submission #643308

# Submission time Handle Problem Language Result Execution time Memory
643308 2022-09-21T17:44:42 Z SirCovidThe19th Feast (NOI19_feast) C++17
100 / 100
298 ms 13896 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define f first
#define s second

int n, k, A[300005]; pll dp[300005][2];

pll better(pll a, pll b){
    if (a.f == b.f) return (a.s < b.s ? a : b);
    return (a.f > b.f ? a : b);
}
bool solve(ll lmb){
    dp[0][0] = {0, 0}; dp[0][1] = {-1e18, 0};

    for (int i = 1; i <= n; i++){
        dp[i][0] = better(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = better({dp[i - 1][0].f + A[i] - lmb, dp[i - 1][0].s + 1}, 
                          {dp[i - 1][1].f + A[i], dp[i - 1][1].s});
    }
    return better(dp[n][0], dp[n][1]).s <= k;
}

int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> A[i];

    ll L = 0, H = 1e15;
    while (L < H){
        ll M = (L + H) / 2;
        solve(M) ? H = M : L = M + 1;
    }
    solve(L);
    cout<<better(dp[n][0], dp[n][1]).f + L * k<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 290 ms 10520 KB Output is correct
2 Correct 280 ms 10720 KB Output is correct
3 Correct 289 ms 10836 KB Output is correct
4 Correct 298 ms 10700 KB Output is correct
5 Correct 274 ms 10708 KB Output is correct
6 Correct 294 ms 10532 KB Output is correct
7 Correct 272 ms 10540 KB Output is correct
8 Correct 289 ms 10780 KB Output is correct
9 Correct 281 ms 10576 KB Output is correct
10 Correct 285 ms 10592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 10508 KB Output is correct
2 Correct 220 ms 10744 KB Output is correct
3 Correct 223 ms 10560 KB Output is correct
4 Correct 245 ms 10676 KB Output is correct
5 Correct 268 ms 10540 KB Output is correct
6 Correct 221 ms 10520 KB Output is correct
7 Correct 252 ms 10852 KB Output is correct
8 Correct 272 ms 10784 KB Output is correct
9 Correct 288 ms 10512 KB Output is correct
10 Correct 226 ms 10876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 10700 KB Output is correct
2 Correct 277 ms 10564 KB Output is correct
3 Correct 279 ms 10696 KB Output is correct
4 Correct 267 ms 10552 KB Output is correct
5 Correct 287 ms 10780 KB Output is correct
6 Correct 279 ms 10652 KB Output is correct
7 Correct 276 ms 10900 KB Output is correct
8 Correct 276 ms 10692 KB Output is correct
9 Correct 283 ms 10832 KB Output is correct
10 Correct 284 ms 10800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 3 ms 316 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 316 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 316 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 10520 KB Output is correct
2 Correct 280 ms 10720 KB Output is correct
3 Correct 289 ms 10836 KB Output is correct
4 Correct 298 ms 10700 KB Output is correct
5 Correct 274 ms 10708 KB Output is correct
6 Correct 294 ms 10532 KB Output is correct
7 Correct 272 ms 10540 KB Output is correct
8 Correct 289 ms 10780 KB Output is correct
9 Correct 281 ms 10576 KB Output is correct
10 Correct 285 ms 10592 KB Output is correct
11 Correct 239 ms 10508 KB Output is correct
12 Correct 220 ms 10744 KB Output is correct
13 Correct 223 ms 10560 KB Output is correct
14 Correct 245 ms 10676 KB Output is correct
15 Correct 268 ms 10540 KB Output is correct
16 Correct 221 ms 10520 KB Output is correct
17 Correct 252 ms 10852 KB Output is correct
18 Correct 272 ms 10784 KB Output is correct
19 Correct 288 ms 10512 KB Output is correct
20 Correct 226 ms 10876 KB Output is correct
21 Correct 276 ms 10700 KB Output is correct
22 Correct 277 ms 10564 KB Output is correct
23 Correct 279 ms 10696 KB Output is correct
24 Correct 267 ms 10552 KB Output is correct
25 Correct 287 ms 10780 KB Output is correct
26 Correct 279 ms 10652 KB Output is correct
27 Correct 276 ms 10900 KB Output is correct
28 Correct 276 ms 10692 KB Output is correct
29 Correct 283 ms 10832 KB Output is correct
30 Correct 284 ms 10800 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 308 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 316 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 3 ms 316 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 3 ms 316 KB Output is correct
59 Correct 3 ms 340 KB Output is correct
60 Correct 2 ms 320 KB Output is correct
61 Correct 278 ms 13544 KB Output is correct
62 Correct 291 ms 13896 KB Output is correct
63 Correct 271 ms 13472 KB Output is correct
64 Correct 280 ms 13804 KB Output is correct
65 Correct 287 ms 13800 KB Output is correct
66 Correct 282 ms 13756 KB Output is correct
67 Correct 275 ms 13480 KB Output is correct
68 Correct 283 ms 13788 KB Output is correct
69 Correct 274 ms 13612 KB Output is correct
70 Correct 269 ms 13400 KB Output is correct