Submission #384334

# Submission time Handle Problem Language Result Execution time Memory
384334 2021-04-01T11:42:42 Z cpp219 Rice Hub (IOI11_ricehub) C++14
100 / 100
17 ms 2540 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
ll b[N];

ll Get(ll L,ll R){
    return b[R] - b[L - 1];
}

bool chk(int m,int n,ll B){
    for (ll i = 0;i < n - m + 1;i++){
        ll L = i,R = i + m - 1;
        ll mid = (L + R)/2; ll val = b[mid] - b[mid - 1];
        ll kq = val*(mid - L + 1) - Get(L,mid) + Get(mid,R) - val*(R - mid + 1);
        if (kq <= B) return 1;
    }
    //exit(0);
    return 0;
}

int besthub(int n,int lim,int a[],ll B){
    ll l,m,h; b[0] = a[0];
    for (ll i = 1;i < n;i++) b[i] = b[i - 1] + a[i]; //cout<<b[4]<<" "<<a[5]; exit(0);
    l = 0; h = n; //cout<<chk(4,n,B); exit(0);
    while(l <= h){
        m = (l + h)/2;
        if (chk(m,n,B)) l = m + 1;
        else h = m - 1;
    }
    return h;
}
/*
ll n,a[N],lim,B;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>lim>>B;
    for (ll i = 1;i <= n;i++) cin>>a[i];
    cout<<besthub(n,lim,a,B);
}
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 17 ms 2540 KB Output is correct
5 Correct 9 ms 1260 KB Output is correct
6 Correct 9 ms 1260 KB Output is correct
7 Correct 15 ms 2284 KB Output is correct
8 Correct 15 ms 2284 KB Output is correct
9 Correct 9 ms 1260 KB Output is correct
10 Correct 9 ms 1260 KB Output is correct
11 Correct 17 ms 2540 KB Output is correct
12 Correct 17 ms 2540 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 10 ms 1260 KB Output is correct
15 Correct 13 ms 2032 KB Output is correct
16 Correct 13 ms 2028 KB Output is correct
17 Correct 15 ms 2284 KB Output is correct
18 Correct 15 ms 2284 KB Output is correct
19 Correct 16 ms 2412 KB Output is correct
20 Correct 16 ms 2412 KB Output is correct