Submission #115266

#TimeUsernameProblemLanguageResultExecution timeMemory
115266oolimryRice Hub (IOI11_ricehub)C++14
0 / 100
1066 ms2592 KiB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B)
{
    long long pre[R];
    pre[0] = X[0];
    for(int i = 1;i < R;i++){
        pre[i] = pre[i-1] + X[i];
    }
    long long ans = 0;
    for(int pos = 1;pos <= L;pos++){
        int lr = lower_bound(X,X+R,pos) - X;
        int rl = upper_bound(X,X+R,pos) - X;
        int low = 0;
        int high = 1000000;
        //cout << pos << " " << lr << " " << rl << " ";
        while(true){
            if(low == high - 1) break;
            int s = (low + high) / 2;
            int ll = lr - s;
            int rr = rl + s;
            if(ll < 0 || rr > R){
                high = s;
                continue;
            }

            long long sum = 0ll;
            sum += pre[lr-1];
            if(ll > 0) sum -= pre[ll-1];
            sum = s * pos - sum;
            sum += pre[rr-1];
            sum -= pre[rl-1];
            sum -= s * pos;
            //cout << "\n" << pos << " " << sum << " " << s << "wow\n";
            if(sum > B){
                high = s;
            }
            else{
                low = s;
            }
        }
        int ll = lr - low;
        int rr = rl + low;
        long long sum = 0ll;
        sum += pre[lr-1];
        if(ll > 0) sum -= pre[ll-1];
        sum = low * pos - sum;
        sum += pre[rr-1];
        sum -= pre[rl-1];
        sum -= low * pos;
        long long nos = rr - ll;
        ans = max(nos, ans);
        //cout << low << "\n";
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...