Submission #1110895

# Submission time Handle Problem Language Result Execution time Memory
1110895 2024-11-10T23:18:25 Z DylanSmith Feast (NOI19_feast) C++17
30 / 100
95 ms 4444 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)

mt19937 rng;

pair<ll, int> check(vector<int> &a, ll cost) {
    pair<ll, int> n = {0, 0}, y = {LLONG_MIN, 0};
    for (int i = 0; i < sz(a); i++) {
        pair<ll, int> n2 = n;
        if (y.first != LLONG_MIN) n2 = max(n2, y);
        pair<ll, int> y2 = {n.first + a[i] - cost, n.second + 1};
        if (y.first != LLONG_MIN) {
            y2 = max(y2, {y.first + a[i], y.second});
            y2 = max(y2, {y.first + a[i] - cost, y.second + 1});
        }
        swap(n, n2);
        swap(y, y2);
    }
    return max(n, y);
}

ll search(vector<int> &a, int K, ll l, ll r) {
    if (l > r) return LLONG_MIN;
    ll mid = (l + r) / 2;
    auto p = check(a, mid);
    if (p.second >= K) {
        ll m = search(a, K, mid + 1, r);
        if (m != LLONG_MIN) return m;
        return p.first + K * mid;
    }
    return search(a, K, l, mid - 1);
}

void solve() {
    int N, K; cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < a.size(); i++) cin >> a[i];
    ll res = search(a, K, 0, LLONG_MAX / 2);
    if (res == LLONG_MIN) cout << "0\n";
    else cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    solve();

    return 0;
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < a.size(); i++) cin >> a[i];
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 61 ms 1360 KB Output is correct
2 Correct 65 ms 4424 KB Output is correct
3 Correct 64 ms 4304 KB Output is correct
4 Correct 63 ms 4444 KB Output is correct
5 Correct 66 ms 4424 KB Output is correct
6 Correct 64 ms 4268 KB Output is correct
7 Correct 66 ms 4372 KB Output is correct
8 Correct 87 ms 4424 KB Output is correct
9 Correct 81 ms 4168 KB Output is correct
10 Correct 64 ms 4296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1360 KB Output is correct
2 Correct 64 ms 1616 KB Output is correct
3 Correct 54 ms 1360 KB Output is correct
4 Correct 52 ms 1360 KB Output is correct
5 Correct 58 ms 4152 KB Output is correct
6 Correct 50 ms 2652 KB Output is correct
7 Correct 75 ms 2640 KB Output is correct
8 Correct 59 ms 4432 KB Output is correct
9 Correct 58 ms 4176 KB Output is correct
10 Correct 52 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 1616 KB Output is correct
2 Correct 80 ms 1372 KB Output is correct
3 Correct 78 ms 1616 KB Output is correct
4 Correct 79 ms 1532 KB Output is correct
5 Correct 78 ms 1628 KB Output is correct
6 Correct 80 ms 1616 KB Output is correct
7 Correct 89 ms 1616 KB Output is correct
8 Correct 78 ms 1616 KB Output is correct
9 Correct 95 ms 1616 KB Output is correct
10 Correct 79 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 1360 KB Output is correct
2 Correct 65 ms 4424 KB Output is correct
3 Correct 64 ms 4304 KB Output is correct
4 Correct 63 ms 4444 KB Output is correct
5 Correct 66 ms 4424 KB Output is correct
6 Correct 64 ms 4268 KB Output is correct
7 Correct 66 ms 4372 KB Output is correct
8 Correct 87 ms 4424 KB Output is correct
9 Correct 81 ms 4168 KB Output is correct
10 Correct 64 ms 4296 KB Output is correct
11 Correct 55 ms 1360 KB Output is correct
12 Correct 64 ms 1616 KB Output is correct
13 Correct 54 ms 1360 KB Output is correct
14 Correct 52 ms 1360 KB Output is correct
15 Correct 58 ms 4152 KB Output is correct
16 Correct 50 ms 2652 KB Output is correct
17 Correct 75 ms 2640 KB Output is correct
18 Correct 59 ms 4432 KB Output is correct
19 Correct 58 ms 4176 KB Output is correct
20 Correct 52 ms 2640 KB Output is correct
21 Correct 86 ms 1616 KB Output is correct
22 Correct 80 ms 1372 KB Output is correct
23 Correct 78 ms 1616 KB Output is correct
24 Correct 79 ms 1532 KB Output is correct
25 Correct 78 ms 1628 KB Output is correct
26 Correct 80 ms 1616 KB Output is correct
27 Correct 89 ms 1616 KB Output is correct
28 Correct 78 ms 1616 KB Output is correct
29 Correct 95 ms 1616 KB Output is correct
30 Correct 79 ms 1616 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Incorrect 1 ms 336 KB Output isn't correct
33 Halted 0 ms 0 KB -