Cod sursa(job #114169)

Utilizator mithyPopovici Adrian mithy Data 12 decembrie 2007 21:38:19
Problema Secventa 3 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <stdio.h>
#define NMax 30001

long n, l, u;
long c[NMax], t[NMax];
long sc[NMax], st[NMax];
double max;

void read();
void solve();
void write();

int main()
{
	read();
	solve();
	write();
	return 0;
}

void solve()
{
	int i, j;
	max = -1;

	for (i = 0; i <= u; i++)
	{
		sc[i] = -1000000000;
		st[i] = 1;
	}
	sc[1] = c[n-1];
	st[1] = t[n-1];

	if (l == 1 && (double)sc[1] / st[1] > max)
		max = (double)sc[1] / st[1];
		
	for (i = n-2; i >= 0; i--)
	{
		//calculez rapoartele secventelor [i, i + j]

		for (j = u; j >= 2; j--)
		{
			sc[j] = sc[j-1] + c[i];
			st[j] = st[j-1] + t[i];
			
			if (j >= l && (double)sc[j] / st[j] > max)
				max = (double)sc[j] / st[j];
		}
		sc[1] = c[i];
		st[1] = t[i];
		if (l == 1 && (double)sc[1] / st[1] > max)
			max = (double)sc[1] / st[1];
	}
}

void read()
{
	int i;
	FILE *fin = fopen("secv3.in", "rt");
	fscanf(fin, "%ld %ld %ld", &n, &l, &u);
	for (i = 0; i < n; i++)
		fscanf(fin, "%ld", &c[i]);
	for (i = 0; i < n; i++)
		fscanf(fin, "%ld", &t[i]);
	fclose(fin);
}
void write()
{
	FILE *fout = fopen("secv3.out", "wt");
	fprintf(fout, "%.2lf\n", max);
	fclose(fout);
}