Mai intai trebuie sa te autentifici.
Cod sursa(job #3281285)
| Utilizator | Data | 28 februarie 2025 22:06:55 | |
|---|---|---|---|
| Problema | Secventa 3 | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 1.19 kb |
#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 st = 0, dr = 30000, sol;
for(int i=1; i<=200; i++) {
double mid = 1.0 * (st + dr) / 2;
if(check(mid) >= 0) sol = mid, st = mid;
else dr = mid;
///cout << st << " " << dr << '\n';
}
fout << fixed << setprecision(2) << sol;
return 0;
}
