Submission #885827

# Submission time Handle Problem Language Result Execution time Memory
885827 2023-12-10T19:56:28 Z VMaksimoski008 Rice Hub (IOI11_ricehub) C++14
100 / 100
16 ms 4708 KB
#include <bits/stdc++.h>
#include "ricehub.h"

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int besthub(int R, int L, int a[], ll B) {
    int ans = 0;

    vector<int> v(R+1);
    vector<ll> pref(R+1);    
    for(int i=0; i<R; i++) {
        v[i+1] = a[i];
        pref[i+1] = a[i] + pref[i];
    }

    auto query = [&](int l, int r) {
        return pref[r] - pref[l-1];
    };

    for(int i=1; i<=R; i++) {
        int l=i, r=R;
        while(l <= r) {
            int j = (l + r) / 2;
            int mid = (i + j) / 2;
            ll total = ((mid - i) * v[mid] - query(i, mid-1)) + (query(mid+1, j) - (j - mid) * v[mid]);

            if(total <= B) ans = max(ans, j - i + 1), l = j + 1;
            else r = j - 1;
        }
    }

    return ans;
}

// int32_t main() {
//     setIO();

//     int R, L;
//     ll B;
//     cin >> R >> L >> B;

//     int v[R];
//     for(int i=0; i<R; i++) cin >> v[i];

//     cout << besthub(R, L, v, B) << '\n';
//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 796 KB Output is correct
2 Correct 2 ms 712 KB Output is correct
3 Correct 14 ms 4696 KB Output is correct
4 Correct 14 ms 4700 KB Output is correct
5 Correct 6 ms 3420 KB Output is correct
6 Correct 7 ms 3416 KB Output is correct
7 Correct 13 ms 4444 KB Output is correct
8 Correct 13 ms 4444 KB Output is correct
9 Correct 7 ms 3420 KB Output is correct
10 Correct 7 ms 3304 KB Output is correct
11 Correct 15 ms 4708 KB Output is correct
12 Correct 14 ms 4700 KB Output is correct
13 Correct 6 ms 3416 KB Output is correct
14 Correct 6 ms 3420 KB Output is correct
15 Correct 10 ms 4184 KB Output is correct
16 Correct 10 ms 4188 KB Output is correct
17 Correct 13 ms 4444 KB Output is correct
18 Correct 12 ms 4444 KB Output is correct
19 Correct 16 ms 4700 KB Output is correct
20 Correct 13 ms 4700 KB Output is correct