Cod sursa(job #60470)

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

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

struct sir
{
    double 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]*1.0;
    c[0].timp = b[0]*1.0;
    c[0].lng = 1;


    double rez = -1.0;


    for ( int i = 1; i < n; ++i )
    {
        if ( ( c[i-1].cost + a[i-1] ) / ( 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 ( c[i].cost / c[i].timp > rez && c[i].lng >= l && c[i].lng <= u )
            rez = c[i].cost / c[i].timp;
    }

//    for ( int i = 0; i < n; ++i )
//        printf("%.2lf %.2lf %d\n", c[i].cost, c[i].timp, c[i].lng);

//    printf("%.2lf %.2lf\n", (c[0].cost+a[1]) / (c[0].timp+b[1]), (double)a[1] / b[1]);

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

	return 0;
}