| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327851 | arman.khachatryan | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
long long besthub(int r, int l, int* a, long long b){
long long pref[r+1];
pref[0]=0;
pref[1]=a[0];
for(int i=2; i<=r; i++){
pref[i]=pref[i-1]+a[i-1];
}
int j=0;
long long cur, ans=1;
for(int i=0; i<r; i++){
while(j<=i){
int mid=(i+j)/2;
cur=(mid-j)*a[mid]-(pref[mid]-pref[j]);
cur+=pref[i+1]-pref[mid+1]-(i-mid)*a[mid];
if(cur>b){
j++;
}else{
ans=max((i-j+1)*1LL, ans);
break;
}
}
}
return ans;
}
int main(){
int r, l;
long long b;
cin>>r>>l>>b;
int a[r];
for(int i=0; i<r; i++){
cin>>a[i];
}
cout<<besthub(r, l, a, b);
}