Cod sursa(job #60438)

Utilizator DastasIonescu Vlad Dastas Data 14 mai 2007 14:55:57
Problema Secventa 3 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#define max 30000

FILE *in = fopen("secv3.in","r"), *out = fopen("secv3.out","w");

struct sir
{
    int cost, timp;
    int lng;
};

int n, l, u;
int a[max];
int b[max];

sir c[max];

void read()
{
    fscanf(in, "%d %d %d", &n, &l, &u);

    for ( int i = 0; i < n; ++i )
        fscanf(in, "%d", &a[i]);

    for ( int i = 0; i < n; ++i )
        fscanf(in, "%d", &b[i]);
}

int main()
{
    read();

    c[0].cost = a[0];
    c[0].timp = b[0];
    c[0].lng = 1;


    double rez = -1.0;


    for ( int i = 1; i < n; ++i )
    {
        if ( (double)(c[i-1].cost + a[i]) / (c[i-1].timp + b[i]) > (double)a[i] / b[i] )
        {
            c[i].cost = c[i-1].cost + a[i];
            c[i].timp = c[i-1].timp + b[i];
            c[i].lng = c[i-1].lng + 1;

        }
        else
        {
            c[i].cost = a[i];
            c[i].timp = b[i];
            c[i].lng = 1;
        }

        if ( (double)c[i].cost / c[i].timp > rez && c[i].lng >= l && c[i].lng <= u )
            rez = (double)c[i].cost / c[i].timp;
    }

    fprintf(out, "%.2lf\n", rez);

	return 0;
}