# Cod sursa(job #1866508)

Utilizator Data 3 februarie 2017 10:54:11 Secventa 3 10 cpp done Arhiva de probleme 1.18 kb
``````#include <fstream>
#include <deque>
#include <algorithm>

using namespace std;

ifstream in("secv3.in");
ofstream out("secv3.out");

const int Max = 30007, sonsuz = 10000000;
int n, l, u, c[Max], t[Max];

double sum2(double x)
{
double toplam[Max], zaman[Max];
toplam[0] = 0;
deque<int> q;
double cevap = -2^61;
for(int i = 1; i <= n; ++i)
{
zaman[i] = c[i] - (x * t[i]);
toplam[i] = toplam[i - 1] + zaman[i];
}
for(int i = 1; i <= n; ++i)
{
while(!q.empty() && toplam[i - l] <= toplam[q.back()])
q.pop_back();
q.push_back(i - l);
if(q.front() < i - u)
q.pop_front();
cevap = max(cevap, toplam[i] - toplam[q.front()]);
}

return cevap;
}

double ara()
{
double st = 0, dr = 30007;
for(int i = 1; i <= 40; ++i)
{
double mid  = (st + dr) / 2;
if(sum2(mid) > 0)
st = mid;
else
dr = mid;
}

return dr;
}

int main()
{
in >> n >> l >> u;
for(int i = 1; i <= n; ++i)
in >> c[i];
for(int i = 1; i <= n; ++i)
in >> t[i];

out << ara();
}
``````