Pagini recente » Cod sursa (job #37239) | Cod sursa (job #2648649) | Cod sursa (job #1215626) | Cod sursa (job #471870) | Cod sursa (job #1992431)
#include <iostream>
#include <fstream>
#include <deque>
#include <iomanip>
#define N 30005
using namespace std;
ifstream f("secv3.in");
ofstream g("secv3.out");
double timp[N],cost[N],rez;
int n,l,u;
deque<int> pos;
double curent(int i)
{
return ((cost[i]-cost[pos.front()])/(timp[i]-timp[pos.front()]));
}
bool cond(int i)
{
return (cost[i]-cost[pos.back()]>timp[i]-timp[pos.back()]);
}
void citire()
{
for(int i=1;i<=n;++i)
{
f>>cost[i];
cost[i]+=cost[i-1];
}
for(int i=1;i<=n;++i)
{
f>>timp[i];
timp[i]+=timp[i-1];
}
}
int main()
{
f>>n>>l>>u;
citire();
for(int i=1;i<l;++i)
{
pos.push_back(i);
}
pos.push_front(0);
for(int i=l;i<=n;++i)
{
if(!pos.empty() && i-pos.front()>u)
{
pos.pop_front();
}
while(!pos.empty() && cond(i) && i-pos.back()<=u-l)
{
pos.pop_back();
}
rez=max(rez,curent(i));
pos.push_back(i);
}
g<<fixed<<setprecision(2)<<rez;
return 0;
}