Cod sursa(job #762034)

Utilizator bia.liliPoenar Liana bia.lili Data 28 iunie 2012 13:49:25
Problema Secventa 3 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream>
using namespace std;
ifstream f("secv3.in");
ofstream g("secv3.out");
int l,u,i,l1,n;
float t1,c1,maxi,timp,cost,c[30001],t[30001];
int main()
{f>>n>>l>>u;
for(i=1;i<=n;++i)
	f>>c[i];
for(i=1;i<=n;++i)
	f>>t[i];
l1=1;
for(i=1;i<=n;++i)
{cost=cost+c[i];
timp=timp+t[i];
if(1+i-l1>u)
{cost=cost-c[l1];
timp=timp-t[l1];
t1=t1-t[i];
c1=c1-c[i];
l1=i-l;
}
if(i>l)
{c1=c1+c[i-l];
t1=t1+t[i-1];
if((cost-c1)/(timp-t1)>cost/timp)
{cost=cost-c1;
timp=timp-t1;
c1=0;
t1=0;
l1=i-l+1;
}}
if(i>=l)
	if(maxi<cost/timp)
		maxi=cost/timp;
}
g.precision(4);
g<<maxi<<'\n';
f.close();
g.close();
return 0;
}