Submission #485691

# Submission time Handle Problem Language Result Execution time Memory
485691 2021-11-09T02:15:42 Z Joo Rice Hub (IOI11_ricehub) C++17
100 / 100
29 ms 3000 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

const int MXN = 1e5+10;
using ll = long long;

int a[MXN];

bool chk(int sz, int R, ll B){
    int med = (sz+1)>>1;
    deque<ll> dq;
    ll rightsum = 0, leftsum = 0;
    for(int i = 1; i <= med; i++){
        leftsum += a[i];
        dq.push_back(a[i]);
    }
    for(int i = med+1; i <= R; i++){
        rightsum += a[i];
        dq.push_back(a[i]);
        if(i >= sz){
            ll tot = rightsum - 1ll*(sz-med)*(dq[med-1]) + 1ll*(med)*dq[med-1] - leftsum;
            if(tot <= B) return true;
            leftsum -= dq.front();
            leftsum += dq[med];
            rightsum -= dq[med];
            dq.pop_front();
        }
    }
    return false;
}

int besthub(int R, int L, int X[], ll B){
    for(int i = 0; i < R; i++){
        a[i+1] = X[i];
    }

    int l = 2, r = R, ans = 1;
    while(l <= r){
        int mid = (l+r)>>1;

        if(chk(mid, R, B)){
            ans = mid;
            l = mid+1;
        }else{
            r = mid-1;
        }
    }
    return ans;
}
/*
int main(void){
    int R,L,B; cin >> R >> L >> B;
    int X[R] = {};
    for(int i = 0; i < R; i++){
        cin >> X[i];
    }
    cout << besthub(R, L, X, B) << "\n";
    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 544 KB Output is correct
3 Correct 21 ms 1900 KB Output is correct
4 Correct 26 ms 2936 KB Output is correct
5 Correct 9 ms 1248 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 20 ms 2668 KB Output is correct
8 Correct 20 ms 2664 KB Output is correct
9 Correct 9 ms 1100 KB Output is correct
10 Correct 9 ms 1080 KB Output is correct
11 Correct 29 ms 2952 KB Output is correct
12 Correct 24 ms 3000 KB Output is correct
13 Correct 10 ms 1212 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 16 ms 2276 KB Output is correct
16 Correct 16 ms 2340 KB Output is correct
17 Correct 21 ms 2668 KB Output is correct
18 Correct 21 ms 2660 KB Output is correct
19 Correct 21 ms 2796 KB Output is correct
20 Correct 21 ms 2800 KB Output is correct