# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1220641 | hmms127 | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
int besthub (int n, int L, int a[], int B) {
int r=0,idx=0,dist=0,ans=0;
for(int i=0;i<n;i++){
dist+=a[i]-a[r];
while(r<i&&(r-idx+1)<(i-r+1)){
dist-=(i+idx-r*2-1)*(a[r+1]-a[r]);
r++;
}
while(dist>B){
dist-=a[r]-a[idx];
idx++;
while(r<i&&(r-idx+1)<(i-r+1)){
dist-=(i+idx-r*2-1)*(a[r+1]-a[r]);
r++;
}
}
ans=max(ans,r-idx+1);
}
return ans;
}