Submission #225650

#TimeUsernameProblemLanguageResultExecution timeMemory
225650chubyxdxdRice Hub (IOI11_ricehub)C++11
68 / 100
1099 ms1792 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>

#define MAX_R  1000000
using namespace std;
typedef long long ll;
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 besthub(int R, int L, int x[], long long B){
  ll maxrice=0;
  for(int i=0;i<R;i++){
    ll curr=B;
    ll currrice=1;
    ll lf=i-1,rh=i+1;
    while(lf>=0 and rh<R){
      ll pos=abs(x[i]-x[lf]);
      ll pos1=abs(x[i]-x[rh]);
      if(curr<pos and curr<pos1)break;
      if(pos<pos1){
	curr-=pos;
	lf--;
	currrice++;
      }
      else{
	curr-=pos1;
	rh++;
	currrice++;
      }
    }
    if(lf>=0){
      while(lf>=0){
	ll pos=abs(x[i]-x[lf]);
	if(curr<pos)break;
	curr-=pos;
	currrice++;
	lf--;
      }
    }
    else{
      while(rh<R){
	ll pos1=abs(x[i]-x[rh]);
	if(curr<pos1)break;
	curr-=pos1;
	currrice++;
	rh++;
      }
    }
    maxrice=max(maxrice,currrice);
  }
  return maxrice;
}/*
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 (stderr)

ricehub.cpp:17:13: warning: 'void read_input()' defined but not used [-Wunused-function]
 static void read_input()
             ^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...