Pagini recente » Cod sursa (job #637656) | Cod sursa (job #2072307) | Cod sursa (job #585072) | Cod sursa (job #2277816) | Cod sursa (job #669831)
Cod sursa(job #669831)
#include <fstream>
#include <iomanip>
#define LE 30006
using namespace std;
ifstream f("secv3.in");
ofstream g("secv3.out");
int n,L,U,LI,i;
float TB,CB,C[LE],T[LE],cost,timp,MAX;
void citire ()
{
f>>n>>L>>U;
for(i=1; i<=n; i++) f>>C[i];
for(i=1; i<=n; i++)f>>T[i];
}
int main()
{
citire();
for(i=1,LI=1; i<=n; i++)
{
cost+=C[i];
timp+=T[i];
if (i-LI+1>U)
{
cost-=C[LI],timp-=T[LI];
TB-=C[LI],CB-=T[LI];
LI=i-L;
}
if (i>L)
{
CB+=C[i-L];
TB+=T[i-L];
if (CB/TB<1)
{
cost-=CB,timp-=TB;
LI=i-L+1;
CB=0,TB=0;
}
}
if (i>=L) MAX=max(MAX,cost/timp);
}
g<<fixed;
g<<setprecision(2)<<MAX<<'\n';
f.close();
g.close();
return 0;
}