Submission #684359

# Submission time Handle Problem Language Result Execution time Memory
684359 2023-01-21T03:45:27 Z kusssso Rice Hub (IOI11_ricehub) C++17
100 / 100
70 ms 2380 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;

ll f[N];

bool check (ll x, ll b, int l, int r, vector<ll> &a) {
    int j = upper_bound(a.begin(), a.end(), x) - a.begin();
    j = min(j, r - 1);
    ll sum = x * (j - l + 1) - (f[j] - f[l - 1]) + (f[r] - f[j]) - x * (r - j);
    return (sum <= b);
}

bool ok (int k, ll b, int n, vector<ll> &a) {
    for (int i = k; i <= n; i++) {
        // ll med = (f[i] - f[i - k]) / k;
        ll med = a[i - k + (k + 1) / 2];
        if (check(med, b, i - k + 1, i, a)) {
            return true;
        }
        if (check(med + 1, b, i - k + 1, i, a)) {
            return true;
        }
        if (check(med - 1, b, i - k + 1, i, a)) {
            return true;
        }
    }
    return false;
}

// int besthub (int r, int l, vector<int> x, ll b) {
int besthub (int r, int l, int x[], ll b) {
    vector<ll> a;
    for (int i = 0; i < r; i++) {
        f[i + 1] = f[i] + x[i];
        a.push_back(x[i]);
    }
    int ans = 0;
    int lo = 0, hi = r;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (ok(mid, b, r, a)) {
            ans = mid;
            lo = mid + 1;
        }
        else {
            hi = mid - 1;
        }
    }
    return ans;
}

// signed main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
//     
    // cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
//     
    // return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 4 ms 476 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 852 KB Output is correct
2 Correct 25 ms 852 KB Output is correct
3 Correct 11 ms 2380 KB Output is correct
4 Correct 11 ms 2312 KB Output is correct
5 Correct 33 ms 1360 KB Output is correct
6 Correct 33 ms 1360 KB Output is correct
7 Correct 9 ms 2376 KB Output is correct
8 Correct 9 ms 2280 KB Output is correct
9 Correct 49 ms 1360 KB Output is correct
10 Correct 48 ms 1348 KB Output is correct
11 Correct 11 ms 2380 KB Output is correct
12 Correct 11 ms 2316 KB Output is correct
13 Correct 66 ms 1360 KB Output is correct
14 Correct 70 ms 1360 KB Output is correct
15 Correct 11 ms 2252 KB Output is correct
16 Correct 8 ms 2252 KB Output is correct
17 Correct 12 ms 2252 KB Output is correct
18 Correct 11 ms 2252 KB Output is correct
19 Correct 11 ms 2256 KB Output is correct
20 Correct 13 ms 2352 KB Output is correct