Cod sursa(job #2632594)

Utilizator stefan.popescuPopescu Stefan stefan.popescu Data 3 iulie 2020 22:40:57
Problema Secventa 3 Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.6 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;
ifstream in ("secv3.in");
ofstream out("secv3.out");
struct tl
{
    int p1, p2;
    tl() {
        p1=0; p2=0;
    }
    tl(int i, int j) {
        p1=i; p2=j;
    }
    friend tl operator + (const tl ths, const tl that) {
        return {ths.p1+that.p1, ths.p2+that.p2};
    }
    friend tl operator - (const tl ths, const tl that) {
        return {ths.p1-that.p1, ths.p2-that.p2};
    }
    void operator +=(const tl that) {
        p1+=that.p1; p2+=that.p2;
    }
    void operator -=(const tl that) {
        p1-=that.p1; p2-=that.p2;
    }

    operator double() {
        return ((double)p1)/p2;
    }

    friend bool operator <=(tl ths, tl that){
        return ths.p1*that.p2<=ths.p2*that.p1;
    }
};

int n, l1, l2, stact;
vector <tl> a;
tl maxi;
inline tl getInterval(int st, int dr)
{
    if(dr<st)
        return {-1000, 1};
    return a[dr]-a[st];
}
int main()
{
    in>>n>>l1>>l2;
    a.resize(n+5, {0, 0});
    for(int i=1; i<=n; i++)
        in>>a[i].p1;
    for(int i=1; i<=n; i++)
        in>>a[i].p2;
    for(int i=2; i<=n; i++)
        a[i]+=a[i-1];

    stact=0; maxi={0, 1};

    for(int i=1; i<=n; i++)
    {
        if(stact+l2<i)
            stact++;

        if(i>=l1)
        {
            if(getInterval(stact, i)<=getInterval(i-l1+1, i))
                stact=i-l1;
            if(maxi<=getInterval(stact, i))
                maxi=getInterval(stact, i);
        }
    }
    out<<fixed<<setprecision(2)<<(double)maxi;
    return 0;
}