#include <bits/stdc++.h>
using namespace std;
int besthub(int n, int p, int a[], long long k)
{
long long prefix[n];
for (long long i=0; i<n; i++)
{
if (i==0)
prefix[i]=a[i];
else
prefix[i]=prefix[i-1]+a[i];
}
long long l=0, r=0, m;
long long maxrice=0;
while (r<n)
{
m=(r+l)/2;
long long distanceright, distanceleft;
distanceright=prefix[r]-prefix[m];
if (l!=0)
distanceleft=prefix[m-1]-prefix[l-1];
else if (m!=0)
distanceleft=prefix[m-1];
else
distanceleft=0;
long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m));
if (budget<=k)
{
maxrice=max(maxrice, r-l+1);
r=r+1;
}
else
{
r=r+1;
l=l+1;
}
}
return maxrice;
}
int main()
{
int n, p;
long long k;
cin >> n >> p >> k;
int a[n];
for (int i=0; i<n; i++)
cin >> a[i];
cout << besthub(n, p, a, k);
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccZtkfDw.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccGEvZVu.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status