Submission #557530

# Submission time Handle Problem Language Result Execution time Memory
557530 2022-05-05T12:39:01 Z Alexandruabcde Feast (NOI19_feast) C++14
100 / 100
736 ms 26912 KB
#include <bits/stdc++.h>

using namespace std;

typedef long double LD;
typedef long long LL;
typedef pair <LD, int> PLDI;
constexpr int NMAX = 3e5 + 5;
constexpr LD INF = 1LL * 1e14;

int N, K;

LD A[NMAX];
PLDI dp[NMAX][2];

PLDI Check (LD penalty) {
    dp[1][0] = {0, 0};
    dp[1][1] = {A[1] - penalty, 1};

    for (int i = 2; 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].first + A[i] - penalty, dp[i-1][0].second + 1),
                       make_pair(dp[i-1][1].first + A[i], dp[i-1][1].second));
    }

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> K;

    for (int i = 1; i <= N; ++ i )
        cin >> A[i];

    int cnt_op = 100;
    LD st = 0, dr = INF;
    while (st <= dr && cnt_op) {
        LD mij = .5 * (st + dr);
        -- cnt_op;

        PLDI pos_ans = Check(mij);
        if (pos_ans.second >= K)
            st = mij;
        else dr = mij;
    }

    PLDI ans = Check(dr);
    LL val = round(ans.first + (LD)K * dr);

    cout << val << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 401 ms 25828 KB Output is correct
2 Correct 447 ms 26368 KB Output is correct
3 Correct 447 ms 26704 KB Output is correct
4 Correct 478 ms 26484 KB Output is correct
5 Correct 450 ms 26444 KB Output is correct
6 Correct 467 ms 25900 KB Output is correct
7 Correct 422 ms 25888 KB Output is correct
8 Correct 421 ms 26424 KB Output is correct
9 Correct 438 ms 25952 KB Output is correct
10 Correct 414 ms 26220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 24356 KB Output is correct
2 Correct 418 ms 24904 KB Output is correct
3 Correct 382 ms 24336 KB Output is correct
4 Correct 393 ms 24652 KB Output is correct
5 Correct 403 ms 25932 KB Output is correct
6 Correct 380 ms 24236 KB Output is correct
7 Correct 385 ms 24904 KB Output is correct
8 Correct 419 ms 26568 KB Output is correct
9 Correct 405 ms 25740 KB Output is correct
10 Correct 399 ms 24772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 26568 KB Output is correct
2 Correct 481 ms 26368 KB Output is correct
3 Correct 503 ms 26480 KB Output is correct
4 Correct 473 ms 26260 KB Output is correct
5 Correct 481 ms 26568 KB Output is correct
6 Correct 483 ms 26572 KB Output is correct
7 Correct 494 ms 26636 KB Output is correct
8 Correct 488 ms 26448 KB Output is correct
9 Correct 483 ms 26804 KB Output is correct
10 Correct 495 ms 26752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 524 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 401 ms 25828 KB Output is correct
2 Correct 447 ms 26368 KB Output is correct
3 Correct 447 ms 26704 KB Output is correct
4 Correct 478 ms 26484 KB Output is correct
5 Correct 450 ms 26444 KB Output is correct
6 Correct 467 ms 25900 KB Output is correct
7 Correct 422 ms 25888 KB Output is correct
8 Correct 421 ms 26424 KB Output is correct
9 Correct 438 ms 25952 KB Output is correct
10 Correct 414 ms 26220 KB Output is correct
11 Correct 407 ms 24356 KB Output is correct
12 Correct 418 ms 24904 KB Output is correct
13 Correct 382 ms 24336 KB Output is correct
14 Correct 393 ms 24652 KB Output is correct
15 Correct 403 ms 25932 KB Output is correct
16 Correct 380 ms 24236 KB Output is correct
17 Correct 385 ms 24904 KB Output is correct
18 Correct 419 ms 26568 KB Output is correct
19 Correct 405 ms 25740 KB Output is correct
20 Correct 399 ms 24772 KB Output is correct
21 Correct 485 ms 26568 KB Output is correct
22 Correct 481 ms 26368 KB Output is correct
23 Correct 503 ms 26480 KB Output is correct
24 Correct 473 ms 26260 KB Output is correct
25 Correct 481 ms 26568 KB Output is correct
26 Correct 483 ms 26572 KB Output is correct
27 Correct 494 ms 26636 KB Output is correct
28 Correct 488 ms 26448 KB Output is correct
29 Correct 483 ms 26804 KB Output is correct
30 Correct 495 ms 26752 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 4 ms 468 KB Output is correct
52 Correct 5 ms 468 KB Output is correct
53 Correct 4 ms 468 KB Output is correct
54 Correct 4 ms 524 KB Output is correct
55 Correct 5 ms 468 KB Output is correct
56 Correct 4 ms 468 KB Output is correct
57 Correct 4 ms 468 KB Output is correct
58 Correct 4 ms 468 KB Output is correct
59 Correct 5 ms 468 KB Output is correct
60 Correct 4 ms 468 KB Output is correct
61 Correct 660 ms 26260 KB Output is correct
62 Correct 651 ms 26912 KB Output is correct
63 Correct 557 ms 26044 KB Output is correct
64 Correct 736 ms 26656 KB Output is correct
65 Correct 671 ms 26752 KB Output is correct
66 Correct 655 ms 26468 KB Output is correct
67 Correct 655 ms 26196 KB Output is correct
68 Correct 499 ms 26712 KB Output is correct
69 Correct 476 ms 26148 KB Output is correct
70 Correct 475 ms 25932 KB Output is correct