Submission #1327829

#TimeUsernameProblemLanguageResultExecution timeMemory
1327829arman.khachatryanRice Hub (IOI11_ricehub)C++20
68 / 100
1095 ms568 KiB
#include <bits/stdc++.h>
using namespace std;
long long besthub(int r, int l, int* a, long long b){
    int j, k=1, ans=0, cntj, cntk=1;
    long long cj, ck=0;
    bool bl;
    for(int i=0; i<r; i++){
        j=i-1;
        cj=0;
        cntj=0;
        bl=true;
        if(k<=i){
            k=i+1;
            ck=0;
            cntk=1;
        }
        while(cj+ck<=b && bl && (j>=0 || k<r)){
            if(0<=j && (k>=r || a[i]-a[j]<=a[k]-a[i])){
                if(b<a[i]-a[j]+cj+ck){
                    bl=false;
                    continue;
                }
                cj+=(a[i]-a[j])*1LL;
                j--;
                cntj++;
            }
            if(k<r && (j<0 || a[i]-a[j]>=a[k]-a[i]) ){
                if(b<a[k]-a[i]+cj+ck){
                    bl=false;
                    continue;
                }
                ck+=(a[k]-a[i])*1LL;
                k++;
                cntk++;
            }
        }
        ans=max(ans, cntj+cntk);
        if(i+1<r){
            ck-=(k-1-i)*(a[i+1]-a[i]);
            cntk--;
        }
    }
    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...