#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
#define rnd() dist(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#define int long long
using namespace std;
unsigned seed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(seed);
uniform_int_distribution<int> dist(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n,m,b;
int x[100005];
bool check(int mid)
{
if(mid==1) return b>=0;
for(int l=1;l+mid-1<=n;++l)
{
int r=l+mid-1;
if(mid%2==0)
{
int x1=(r+l-1)/2,x2=(r+l+1)/2;
if(x[r]-x[x2-1]-x[x1]+x[l-1]<=b) return true;
}
else
{
int x1=(l+r)/2-1,x2=(l+r)/2+1;
if(x[r]-x[x2-1]-x[x1]+x[l-1]<=b) return true;
}
}
return false;
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
read(n);read(m);read(b);
for(int i=1;i<=n;++i)
{
read(x[i]);
x[i]+=x[i-1];
}
int l=1,r=n;
while(l<r)
{
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else
r=mid-1;
}
writeln(l);
return 0;
}
Compilation message
ricehub.cpp: In function 'int main()':
ricehub.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int mid=l+r+1>>1;
| ~~~^~
/usr/bin/ld: /tmp/cchenWj6.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc48agT5.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cchenWj6.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status