Cod sursa(job #2607556)

Utilizator alex_benescuAlex Ben alex_benescu Data 29 aprilie 2020 21:29:25
Problema Secventa 3 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.1 kb
#include <stdio.h>
#include <ctype.h>
#define NMAX 30003
#define EPS 0.001
#define MAXVAL 33554432
#define X 29998
#define MAXLOG10 10
#define BUFSIZE (128 * 1024)
using namespace std;
int p10[MAXLOG10 + 1] = { 0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
int rpos; char rbuf[BUFSIZE];
static inline void initRead() {
  rpos = BUFSIZE - 1;
}
static inline char readChar() {
  if ( !(rpos = (rpos + 1) & (BUFSIZE - 1)) )
    fread( rbuf, 1, BUFSIZE, stdin );
  return rbuf[rpos];
}
int readInt() {
  int ch, res = 0;
  while ( isspace( ch = readChar() ) );
  do
    res = 10 * res + ch - '0';
  while ( isdigit( ch = readChar() ) );
  return res;
}
int vcost[NMAX], vtimp[NMAX];
float v[X + 3];
int main() {
  freopen ( "secv3.in", "r", stdin );
  freopen ( "secv3.out", "w", stdout );
  int n, lmin, lmax, i, scost, stimp, k;
  float r, mij;

  initRead();
  n = readInt();
  lmin = readInt();
  lmax = readInt();
  for( i = 0; i < n; i++ )
    vcost[i] = readInt();
  for( i = 0; i < n; i++ )
    vtimp[i] = readInt();

  r=0;
  if( lmax - lmin > X ) {
    for( k = lmin; k <= lmax; k += 26 ) {
      scost = stimp = 0;
      for( i = 0; i < k; i++ ) {
        scost += vcost[i];
        stimp += vtimp[i];
      }
      mij = (float) scost / stimp;
      for( i = k; i < n; i++ ){
        scost = scost - vcost[i - k] + vcost[i];
        stimp = stimp - vtimp[i - k] + vtimp[i];
        if( (float) scost / stimp > mij )
          mij = (float) scost / stimp;
      }
      if( r < mij )
        r = mij;
    }
  }
  else {
    for( k = lmin; k <= lmax; k += 13 ) {
      scost = stimp = 0;
      for( i = 0; i < k; i++ ) {
        scost += vcost[i];
        stimp += vtimp[i];
      }
      mij = (float) scost / stimp;
      for( i = k; i < n; i++ ){
        scost = scost - vcost[i - k] + vcost[i];
        stimp = stimp - vtimp[i - k] + vtimp[i];
        if( (float) scost / stimp > mij )
          mij = (float) scost / stimp;
      }
      if( r < mij )
        r = mij;
    }
  }

  printf( "%f\n", r );
  return 0;
}