Submission #440616

# Submission time Handle Problem Language Result Execution time Memory
440616 2021-07-02T14:18:54 Z julian33 Rice Hub (IOI11_ricehub) C++14
100 / 100
20 ms 4052 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)(x.size())
#define pb push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}

const int mxN=1e5+5;

ll pref[mxN],suff[mxN],a[mxN],n,l,b,above,below;

bool check(int k){
    // cout<<k<<"\n";
    k--;
    for(int i=1;i<=n;i++){
        int sub=k/2;
        if(a[i]>l)
            return 0;
        if(i-sub-1<0 || i+k-sub>n)
            continue;
        below=pref[i-1]-pref[i-sub-1];
        above=suff[i+1]-suff[i+k-sub+1];
        if(sub*a[i]-below + above-(k-sub)*a[i] <= b)
            return 1;
    }
    return 0;
}

int besthub(int R, int L, int X[], long long B){
    n=R; l=L; b=B;
    for(int i=1;i<=n;i++)
        a[i]=X[i-1];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
        pref[i]=a[i]+pref[i-1];
    for(int i=n;i>=1;i--)
        suff[i]=a[i]+suff[i+1];
    int l=1; int r=n;
    int ans=1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            ans=mid; l=mid+1;
        } else{
            r=mid-1;
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 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 312 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 236 KB Output is correct
15 Correct 0 ms 308 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 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 0 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 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 972 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 18 ms 4052 KB Output is correct
4 Correct 19 ms 4004 KB Output is correct
5 Correct 14 ms 1996 KB Output is correct
6 Correct 9 ms 2000 KB Output is correct
7 Correct 20 ms 3788 KB Output is correct
8 Correct 16 ms 3804 KB Output is correct
9 Correct 9 ms 1984 KB Output is correct
10 Correct 9 ms 1984 KB Output is correct
11 Correct 18 ms 4032 KB Output is correct
12 Correct 20 ms 4016 KB Output is correct
13 Correct 9 ms 2028 KB Output is correct
14 Correct 9 ms 1980 KB Output is correct
15 Correct 18 ms 3064 KB Output is correct
16 Correct 18 ms 3024 KB Output is correct
17 Correct 16 ms 3644 KB Output is correct
18 Correct 16 ms 3660 KB Output is correct
19 Correct 17 ms 3832 KB Output is correct
20 Correct 17 ms 3904 KB Output is correct