# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
422240 | ScarletS | 쌀 창고 (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int a[], long long B)
{
int l=0,r=R,m,x,y;
bool ok;
//cout<<L<<"!!\n";
long long cur;
while (l<r)
{
ok=0;
m=l+(r-l)/2+1;
//cout<<m<<"!\n";
cur=0;
x=0;y=m-1;
for (int i=0;i<=y/2;++i)
cur-=a[i];
for (int i=y/2+1;i<m;++i)
cur+=a[i];
//cout<<cur<<" ";
// cout<<1LL*a[(x+y)/2]*((m-1)/2+1)<<" "<<-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<"\n";
//cout<<cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<" ";
if (cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<=B)
ok=1;
for (++x,++y;y<R;++x,++y)
{
//cout<<"\n"<<x<<" "<<y<<"\n";
cur+=a[x-1];
cur+=a[y];
cur-=a[(x+y)/2]*2;
// cout<<"+ "<<a[x-1]<<"\n";
// cout<<"+ "<<a[y]<<"\n";
// cout<<"- 2*"<<a[(x+y)/2]<<"\n";
if (cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<=B)
ok=1;
//cout<<cur<<" ";
//cout<<cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<" ";
}
//cout<<"\n";
if (ok)
l=m;
else
r=m-1;
}
return l;
}
int main()
{
int r,l,b;
cin>>r>>l>>b;
int x[r];
for (int i=0;i<r;++i)
cin>>x[i];
cout<<besthub(r,l,x,b);
return 0;
}