Submission #927877

# Submission time Handle Problem Language Result Execution time Memory
927877 2024-02-15T13:25:28 Z sleepntsheep Feast (NOI19_feast) C++17
100 / 100
489 ms 25604 KB
#include <cstdio>
#include <cmath>
#include <climits>
#include <functional>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;

#define N 300005
#define ALL(x) x.begin(), x.end()

int n, k, a[N];
long long p[N];
pair<long double, int> dp[N][2];
const long double EPS = 1e-3;

int check(long double lambda)
{
    dp[0][1] = make_pair(-1e18, 0);
    for (int i = 1; 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] - lambda, 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]).second >= k;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    long double l = 0, r = 1e18;
    while (l + EPS < r)
    {
        long double y = (l+r)/2;
        if (check(y)) l = y;
        else r = y;
    }

    check(l);
    cout << (long long)round(k * l + max(dp[n][0], dp[n][1]).first);

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 372 ms 20308 KB Output is correct
2 Correct 375 ms 23116 KB Output is correct
3 Correct 382 ms 25424 KB Output is correct
4 Correct 376 ms 23128 KB Output is correct
5 Correct 378 ms 23284 KB Output is correct
6 Correct 369 ms 22868 KB Output is correct
7 Correct 369 ms 23036 KB Output is correct
8 Correct 375 ms 23132 KB Output is correct
9 Correct 371 ms 22832 KB Output is correct
10 Correct 373 ms 23088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 373 ms 20236 KB Output is correct
2 Correct 381 ms 23260 KB Output is correct
3 Correct 374 ms 21328 KB Output is correct
4 Correct 370 ms 21340 KB Output is correct
5 Correct 380 ms 22892 KB Output is correct
6 Correct 370 ms 21340 KB Output is correct
7 Correct 377 ms 23552 KB Output is correct
8 Correct 388 ms 25172 KB Output is correct
9 Correct 375 ms 23020 KB Output is correct
10 Correct 373 ms 21340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 395 ms 20048 KB Output is correct
2 Correct 405 ms 23376 KB Output is correct
3 Correct 396 ms 23124 KB Output is correct
4 Correct 390 ms 23376 KB Output is correct
5 Correct 393 ms 23268 KB Output is correct
6 Correct 399 ms 23300 KB Output is correct
7 Correct 399 ms 25168 KB Output is correct
8 Correct 397 ms 23124 KB Output is correct
9 Correct 406 ms 25372 KB Output is correct
10 Correct 401 ms 25364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 616 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 372 ms 20308 KB Output is correct
2 Correct 375 ms 23116 KB Output is correct
3 Correct 382 ms 25424 KB Output is correct
4 Correct 376 ms 23128 KB Output is correct
5 Correct 378 ms 23284 KB Output is correct
6 Correct 369 ms 22868 KB Output is correct
7 Correct 369 ms 23036 KB Output is correct
8 Correct 375 ms 23132 KB Output is correct
9 Correct 371 ms 22832 KB Output is correct
10 Correct 373 ms 23088 KB Output is correct
11 Correct 373 ms 20236 KB Output is correct
12 Correct 381 ms 23260 KB Output is correct
13 Correct 374 ms 21328 KB Output is correct
14 Correct 370 ms 21340 KB Output is correct
15 Correct 380 ms 22892 KB Output is correct
16 Correct 370 ms 21340 KB Output is correct
17 Correct 377 ms 23552 KB Output is correct
18 Correct 388 ms 25172 KB Output is correct
19 Correct 375 ms 23020 KB Output is correct
20 Correct 373 ms 21340 KB Output is correct
21 Correct 395 ms 20048 KB Output is correct
22 Correct 405 ms 23376 KB Output is correct
23 Correct 396 ms 23124 KB Output is correct
24 Correct 390 ms 23376 KB Output is correct
25 Correct 393 ms 23268 KB Output is correct
26 Correct 399 ms 23300 KB Output is correct
27 Correct 399 ms 25168 KB Output is correct
28 Correct 397 ms 23124 KB Output is correct
29 Correct 406 ms 25372 KB Output is correct
30 Correct 401 ms 25364 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 468 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 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 464 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 3 ms 616 KB Output is correct
55 Correct 3 ms 600 KB Output is correct
56 Correct 4 ms 604 KB Output is correct
57 Correct 3 ms 604 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
59 Correct 3 ms 860 KB Output is correct
60 Correct 3 ms 480 KB Output is correct
61 Correct 484 ms 23120 KB Output is correct
62 Correct 489 ms 25604 KB Output is correct
63 Correct 420 ms 23208 KB Output is correct
64 Correct 483 ms 23288 KB Output is correct
65 Correct 474 ms 23324 KB Output is correct
66 Correct 466 ms 23124 KB Output is correct
67 Correct 460 ms 23212 KB Output is correct
68 Correct 399 ms 23296 KB Output is correct
69 Correct 391 ms 23208 KB Output is correct
70 Correct 385 ms 23196 KB Output is correct