Pagini recente » Rating Fortza Dinamo (LyonHater) | Cod sursa (job #3177583) | Cod sursa (job #3281284) | Diferente pentru propuneri/6-arhiva-educationala intre reviziile 2 si 16 | Cod sursa (job #3281292)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv3.in");
ofstream fout("secv3.out");
int n, st, dr;
double a[30010];
struct Iris {
int cost, timp;
}v[30010];
deque<int> dq;
inline double check(double x) {
for(int i=1; i<=n; i++) a[i] = v[i].cost - x * v[i].timp;
while(!dq.empty()) dq.pop_back();
double rez = -2e9;
for(int i=st; i<=n; i++) {
while(!dq.empty() && a[i] - a[i - st] <= a[i] - a[dq.back()]) dq.pop_back();
dq.push_back(i - st);
while(!dq.empty() && i - dq.front() >= dr) dq.pop_front();
rez = max(rez, a[i] - a[dq.front()]);
}
return rez;
}
int main()
{
fin >> n >> st >> dr;
for(int i=1; i<=n; i++) {
int x; fin >> x;
v[i].cost = v[i - 1].cost + x;
}
for(int i=1; i<=n; i++) {
int x; fin >> x;
v[i].timp = v[i - 1].timp + x;
}
double st1 = 0, dr1 = 30000, sol = -2e9;
while(dr1 - st1 > 1e-3) {
double mid = 1.0 * (st1 + dr1) / 2;
if(check(mid) >= 0) sol = max(sol, mid), st1 = mid;
else dr1 = mid;
///cout << st1 << " " << dr1 << '\n';
}
fout << fixed << setprecision(2) << sol;
return 0;
}