# Cod sursa(job #1870453)

Utilizator Data 6 februarie 2017 17:40:41 Secventa 3 10 cpp done Arhiva de probleme 1.19 kb
``````#include <fstream>
#include <deque>
#include <algorithm>

using namespace std;

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

const double sonsuz = 1e7;
const int Max = 30007;
int n, l, u, c[Max], t[Max];

double sum2(double sayi)
{
double v[Max], toplam[Max];
toplam[0] = 0;
deque<int> q;
double sonsuz2 = -30000000;

for(int i = 1; i <= n; ++i)
{
v[i] = c[i] - (sayi * t[i]);
toplam[i] = toplam[i - 1] + v[i];
}
for(int i = 1; i <= n; ++i)
{
while(!q.empty() && toplam[i - 1] <= toplam[q.back()])
q.pop_back();
q.push_back(i - 1);
if(q.front() < i - u)
q.pop_front();
sonsuz2 = max(sonsuz2, toplam[i] - toplam[q.front()]);
}
return sonsuz2;
}

double cevap()
{
double st = 0, dr = Max;
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 << cevap();
}
``````