Submission #963837

# Submission time Handle Problem Language Result Execution time Memory
963837 2024-04-15T19:08:41 Z kh0i Feast (NOI19_feast) C++17
100 / 100
370 ms 26940 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

using ll = long long;
using pii = pair<int, int>;

#define F first
#define S second
#define double long double
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

const int N = 3e5 + 3;
const double eps = 1e-3;

int n;
pair<double, int> f[N][2];
double k, a[N];

pair<double, int> calc(double cost){
    f[0][0] = {0, 0};
    f[0][1] = {-1e15, 0};
    for(int i = 1; i <= n; ++i){
        f[i][0] = max(f[i - 1][0], f[i - 1][1]);
        f[i][1] = max((pair<double, int>){f[i - 1][0].F + a[i] - cost, f[i - 1][0].S + 1}, pair<double, int>{f[i - 1][1].F + a[i], f[i - 1][1].S});
    }
    return max(f[n][0], f[n][1]);
}

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    double l = 0, r = 1e15;
    while(r - l > eps){
        double mid = (l + r) / 2;
        if(calc(mid).S >= k)
            l = mid;
        else
            r = mid;
    }
    pair<double, int> res = calc(l);
    cout << (ll)round(res.F + l * k);
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    #define task "troll"
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef LOCAL
        cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif
    return 0;
}

Compilation message

feast.cpp: In function 'int32_t main()':
feast.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 240 ms 23348 KB Output is correct
2 Correct 241 ms 26616 KB Output is correct
3 Correct 248 ms 26784 KB Output is correct
4 Correct 264 ms 26644 KB Output is correct
5 Correct 250 ms 26528 KB Output is correct
6 Correct 247 ms 26160 KB Output is correct
7 Correct 242 ms 26152 KB Output is correct
8 Correct 248 ms 26608 KB Output is correct
9 Correct 252 ms 26208 KB Output is correct
10 Correct 253 ms 26424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 23476 KB Output is correct
2 Correct 243 ms 25036 KB Output is correct
3 Correct 219 ms 24556 KB Output is correct
4 Correct 238 ms 24572 KB Output is correct
5 Correct 239 ms 26096 KB Output is correct
6 Correct 231 ms 24548 KB Output is correct
7 Correct 236 ms 24920 KB Output is correct
8 Correct 272 ms 26472 KB Output is correct
9 Correct 257 ms 26116 KB Output is correct
10 Correct 250 ms 24928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 23632 KB Output is correct
2 Correct 282 ms 26468 KB Output is correct
3 Correct 274 ms 26676 KB Output is correct
4 Correct 290 ms 26472 KB Output is correct
5 Correct 276 ms 26672 KB Output is correct
6 Correct 283 ms 26804 KB Output is correct
7 Correct 284 ms 26884 KB Output is correct
8 Correct 288 ms 26676 KB Output is correct
9 Correct 304 ms 26940 KB Output is correct
10 Correct 284 ms 26708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 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 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 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 2392 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 2392 KB Output is correct
17 Correct 1 ms 2648 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 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 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 2392 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 2392 KB Output is correct
17 Correct 1 ms 2648 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 2396 KB Output is correct
21 Correct 2 ms 2580 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2552 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 3 ms 2396 KB Output is correct
27 Correct 3 ms 2400 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 3 ms 2576 KB Output is correct
30 Correct 3 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 23348 KB Output is correct
2 Correct 241 ms 26616 KB Output is correct
3 Correct 248 ms 26784 KB Output is correct
4 Correct 264 ms 26644 KB Output is correct
5 Correct 250 ms 26528 KB Output is correct
6 Correct 247 ms 26160 KB Output is correct
7 Correct 242 ms 26152 KB Output is correct
8 Correct 248 ms 26608 KB Output is correct
9 Correct 252 ms 26208 KB Output is correct
10 Correct 253 ms 26424 KB Output is correct
11 Correct 252 ms 23476 KB Output is correct
12 Correct 243 ms 25036 KB Output is correct
13 Correct 219 ms 24556 KB Output is correct
14 Correct 238 ms 24572 KB Output is correct
15 Correct 239 ms 26096 KB Output is correct
16 Correct 231 ms 24548 KB Output is correct
17 Correct 236 ms 24920 KB Output is correct
18 Correct 272 ms 26472 KB Output is correct
19 Correct 257 ms 26116 KB Output is correct
20 Correct 250 ms 24928 KB Output is correct
21 Correct 292 ms 23632 KB Output is correct
22 Correct 282 ms 26468 KB Output is correct
23 Correct 274 ms 26676 KB Output is correct
24 Correct 290 ms 26472 KB Output is correct
25 Correct 276 ms 26672 KB Output is correct
26 Correct 283 ms 26804 KB Output is correct
27 Correct 284 ms 26884 KB Output is correct
28 Correct 288 ms 26676 KB Output is correct
29 Correct 304 ms 26940 KB Output is correct
30 Correct 284 ms 26708 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 2392 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 2392 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 2392 KB Output is correct
47 Correct 1 ms 2648 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 2396 KB Output is correct
51 Correct 2 ms 2580 KB Output is correct
52 Correct 3 ms 2396 KB Output is correct
53 Correct 3 ms 2396 KB Output is correct
54 Correct 3 ms 2552 KB Output is correct
55 Correct 3 ms 2396 KB Output is correct
56 Correct 3 ms 2396 KB Output is correct
57 Correct 3 ms 2400 KB Output is correct
58 Correct 2 ms 2396 KB Output is correct
59 Correct 3 ms 2576 KB Output is correct
60 Correct 3 ms 2532 KB Output is correct
61 Correct 343 ms 26436 KB Output is correct
62 Correct 353 ms 26732 KB Output is correct
63 Correct 303 ms 26376 KB Output is correct
64 Correct 353 ms 26812 KB Output is correct
65 Correct 370 ms 26608 KB Output is correct
66 Correct 353 ms 26732 KB Output is correct
67 Correct 365 ms 26408 KB Output is correct
68 Correct 291 ms 26712 KB Output is correct
69 Correct 283 ms 26480 KB Output is correct
70 Correct 309 ms 26296 KB Output is correct