Submission #1112898

# Submission time Handle Problem Language Result Execution time Memory
1112898 2024-11-15T08:21:27 Z KhoaHo Feast (NOI19_feast) C++17
100 / 100
137 ms 15180 KB
#include <bits/stdc++.h>
using namespace std;
#define task "test"
#define pb push_back
#define SZ(a) (a).begin(), (a).end()
#define SZZ(a, Begin, End) (a) + (Begin), (a) + (Begin) + (End)
#define BIT(a) (1LL << (a))
#define vec vector
#define fi first
#define se second
#define mp make_pair
#define MASK(x, i) (((x) >> (i))&1)
typedef long long ll;
typedef pair<ll, ll> ii;
template <class T>
inline bool maximize(T &a, const T &b) { return (a < b ? (a = b, 1) : 0); }
template <class T>
inline bool minimize(T &a, const T &b) { return (a > b ? (a = b, 1) : 0); }
void fastio() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    else if (fopen(task ".in", "r")) {
        freopen(task ".in", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
}
const int N = int(3e5) + 100;
const ll INF = 1e18;
int n, k;
ll a[N];
ii dp[N][2];
void init() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
}
// dp(i, 0) = dp(i - 1, 0) + a  
ii calc(ll C) {
    dp[1][0] = ii(0, 0);
    dp[1][1] = ii(a[1] - C, 1);
    for(int i = 2; i <= n; i++) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);

        dp[i][1] = max(ii(dp[i - 1][0].fi + a[i] - C, dp[i - 1][0].se + 1),
                       ii(dp[i - 1][1].fi + a[i], dp[i - 1][1].se));
    }
    return max(dp[n][0], dp[n][1]);
}
void process(const int &tc) {
    ll l = 0, r = 1e18;
    ll ans = 0;
    while(l <= r) {
        ll mid = l + (r - l)/2;
        if(calc(mid).se <= k) {
            ans = mid;
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    ii res = calc(ans);
    cout << res.fi + res.se * ans;
}
int main() {
    fastio();
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        init();
        process(i);
    }
    return 0;
}

Compilation message

feast.cpp: In function 'void fastio()':
feast.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(task ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 61 ms 14420 KB Output is correct
2 Correct 62 ms 14664 KB Output is correct
3 Correct 66 ms 14944 KB Output is correct
4 Correct 62 ms 14928 KB Output is correct
5 Correct 61 ms 14672 KB Output is correct
6 Correct 62 ms 14416 KB Output is correct
7 Correct 63 ms 14416 KB Output is correct
8 Correct 62 ms 14928 KB Output is correct
9 Correct 64 ms 14616 KB Output is correct
10 Correct 76 ms 14664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 12880 KB Output is correct
2 Correct 54 ms 13136 KB Output is correct
3 Correct 57 ms 12568 KB Output is correct
4 Correct 55 ms 12880 KB Output is correct
5 Correct 66 ms 14620 KB Output is correct
6 Correct 57 ms 12912 KB Output is correct
7 Correct 56 ms 13340 KB Output is correct
8 Correct 66 ms 14920 KB Output is correct
9 Correct 72 ms 14564 KB Output is correct
10 Correct 58 ms 13128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 14940 KB Output is correct
2 Correct 93 ms 13640 KB Output is correct
3 Correct 88 ms 14928 KB Output is correct
4 Correct 92 ms 13732 KB Output is correct
5 Correct 91 ms 13952 KB Output is correct
6 Correct 103 ms 14920 KB Output is correct
7 Correct 103 ms 14920 KB Output is correct
8 Correct 91 ms 14924 KB Output is correct
9 Correct 95 ms 15176 KB Output is correct
10 Correct 97 ms 13896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 14420 KB Output is correct
2 Correct 62 ms 14664 KB Output is correct
3 Correct 66 ms 14944 KB Output is correct
4 Correct 62 ms 14928 KB Output is correct
5 Correct 61 ms 14672 KB Output is correct
6 Correct 62 ms 14416 KB Output is correct
7 Correct 63 ms 14416 KB Output is correct
8 Correct 62 ms 14928 KB Output is correct
9 Correct 64 ms 14616 KB Output is correct
10 Correct 76 ms 14664 KB Output is correct
11 Correct 54 ms 12880 KB Output is correct
12 Correct 54 ms 13136 KB Output is correct
13 Correct 57 ms 12568 KB Output is correct
14 Correct 55 ms 12880 KB Output is correct
15 Correct 66 ms 14620 KB Output is correct
16 Correct 57 ms 12912 KB Output is correct
17 Correct 56 ms 13340 KB Output is correct
18 Correct 66 ms 14920 KB Output is correct
19 Correct 72 ms 14564 KB Output is correct
20 Correct 58 ms 13128 KB Output is correct
21 Correct 90 ms 14940 KB Output is correct
22 Correct 93 ms 13640 KB Output is correct
23 Correct 88 ms 14928 KB Output is correct
24 Correct 92 ms 13732 KB Output is correct
25 Correct 91 ms 13952 KB Output is correct
26 Correct 103 ms 14920 KB Output is correct
27 Correct 103 ms 14920 KB Output is correct
28 Correct 91 ms 14924 KB Output is correct
29 Correct 95 ms 15176 KB Output is correct
30 Correct 97 ms 13896 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 520 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 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 348 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 2 ms 336 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 2 ms 336 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 2 ms 336 KB Output is correct
60 Correct 2 ms 484 KB Output is correct
61 Correct 126 ms 14840 KB Output is correct
62 Correct 120 ms 15176 KB Output is correct
63 Correct 107 ms 14664 KB Output is correct
64 Correct 129 ms 14928 KB Output is correct
65 Correct 131 ms 15116 KB Output is correct
66 Correct 137 ms 15180 KB Output is correct
67 Correct 128 ms 14672 KB Output is correct
68 Correct 92 ms 14920 KB Output is correct
69 Correct 88 ms 14672 KB Output is correct
70 Correct 86 ms 14784 KB Output is correct