Submission #493546

#TimeUsernameProblemLanguageResultExecution timeMemory
493546AlexRex0Rice Hub (IOI11_ricehub)C++14
100 / 100
16 ms3276 KiB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

long long int pos[100002];
long long int acumulado[100002];

long long int cal(int l, int r, int m){
    long long int suma = 0;
    if(r > m){
        suma+= (acumulado[r] - acumulado[m]) - ((r - m) * pos[m]);
    }
    if(l < m){
        suma+= ((m - l) * pos[m]) - (acumulado[m - 1] - acumulado[l - 1]);
    }
    return suma;
}

int besthub(int R, int L, int X[], long long B)
{
    for(int i = 0; i < R; ++i){
        pos[i + 1] = X[i];
        acumulado[i + 1] = acumulado[i] + pos[i + 1];
    }
    int l = 1, r = 1, m = 1, ans = 1, n = R;
    while(l < n || r < n){
        m = (l + r) / 2;
        if(cal(l, r, m) <= B){
            ans = max(ans, r - l + 1);
            if(r < n){
                r++;
            }else{
                l++;
            }
        }else{
            l++;
        }
    }
    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...