#include "ricehub.h"
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
int besthub(int R, int L, int X[], long long B)
{
ll ans=1;
ll plus,l,r;
l=1;
r=R;
bool ok=false;
while(l<r)
{
if(plus==l || plus==r)
break;
ok=false;
plus=(l+r)/2;
bool pre=false;
ll curr=0;
for(int i=0;i<=R-plus;i++)
{
ll med;
if(!pre)
{
med=(i+i+plus-1)/2;
for(int j=i;j<i+plus;j++)
curr+=abs(X[med]-X[j]);
pre=true;
}
else
{
med++;
ll dif=abs(X[med]-X[med-1]);
curr+=abs(i-med)*dif;
curr-=(plus-abs(i-med-1))*dif;
curr+=abs(X[med]-X[i+plus-1]);
curr-=abs(X[med-1]-X[i-1]);
}
if(curr<=B)
{
ans=max(plus,ans);
ok=true;
break;
}
}
if(ok)
l=plus;
else
r=plus;
}
//cout<<'\n'<<ans<<'\n';
return ans;
}
#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#define MAX_R 1000000
static int R, L;
static long long B;
static int X[MAX_R];
static int solution;
inline
void my_assert(int e) {if (!e) abort();}
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;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:21:1: warning: 'plus' may be used uninitialized in this function [-Wmaybe-uninitialized]
21 | if(plus==l || plus==r)
| ^~
/usr/bin/ld: /tmp/ccxKno4J.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccqHu8JL.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status