Cod sursa(job #3281298)

Utilizator Cyb3rBoltSbora Ioan-David Cyb3rBolt Data 28 februarie 2025 22:46:22
Problema Secventa 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 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 minim = 2e9, poz;
    for(int i=0; i<st; i++)
        if(a[st] - a[i] <= minim) minim = a[st] - a[i], poz = i;
    dq.push_back(poz);
    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;
}