# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1247883 | LM1 | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
#define MAX_R 1000000
using namespace std;
const int N=1e5+5;
static int R, L;
static long long B;
static int X[MAX_R];
static int solution;
long long pr[N],ans=-1e18;
inline
void my_assert(int e) {if (!e) abort();}
long long solve(int l){
int l1=l,r1=R;
while(l1<r1){
int mid=(l1+r1+1)/2,k=(l+mid)/2;
if(X[k-1]*(k-l+1)-(pr[k]-pr[l-1])+(pr[mid]-pr[k])-(mid-k)*X[k-1]>B)r1=mid-1;
else l1=mid;
}
return l1-l+1;
}
int besthub(int R,int L,int X[],int B){
for(int i=0;i<R;i++)pr[i+1]+=pr[i]+X[i];
for(int i=1;i<=R;i++)ans=max(solve(i),ans);
return ans;
}
static void read_input()
{
int i;
my_assert(3==scanf("%d %d %lld",&R,&L,&B));
for(i=0; i<R; i++)
my_assert(1==scanf("%d",&X[i]));
my_assert(1==scanf("%d",&solution));
}
//int main()
//{
// int ans;
// read_input();
// ans = besthub(R,L,X,B);
// if(ans==solution)
// printf("Correct.\n");
// else
// printf("Incorrect. Returned %d instead of %d.\n",ans,solution);
//
// return 0;
//}