Submission #1005708

#TimeUsernameProblemLanguageResultExecution timeMemory
1005708vjudge1Rice Hub (IOI11_ricehub)C++17
100 / 100
9 ms2652 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long const ll sz=50005; ll a[sz], b[sz], d[sz], p[sz]; int besthub(int num, int le, int x[], long long k) { for(int i=0; i<num; i++){ p[i+1]=p[i]+x[i]; } ll l=1, r=1, ans=0; while(r<=num){ ll mid=(l+r)/2, num; if((l+r)%2){ ll num1=x[mid-1]*(mid-l)-p[mid-1]+p[l-1]+p[r]-p[mid]-x[mid-1]*(r-mid); mid++; ll num2=x[mid-1]*(mid-l)-p[mid-1]+p[l-1]+p[r]-p[mid]-x[mid-1]*(r-mid); num=min(num1, num2); } else num=x[mid-1]*(mid-l)-p[mid-1]+p[l-1]+p[r]-p[mid]-x[mid-1]*(r-mid); //cout<<l<<' '<<r<<' '<<num<<' '<<p[r-1]-p[mid-1]<<endl; if(num<=k){ ans=max(ans, r-l+1); r++; } else{ l++; } } return ans; } /* {} [] 5 20 6 1 2 10 12 14 3 1 3 13 25 39 12*2-10+39-13-12*1=12+16 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...