Cod sursa(job #2059319)

Utilizator mihai.alphamihai craciun mihai.alpha Data 6 noiembrie 2017 21:15:56
Problema Secventa 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3e4 + 5;

int n, l, u;
int c[MAXN], t[MAXN];

#define BUF 1 << 17
char buf[BUF];
int pos = BUF;

inline char next()  {
    if(pos == BUF)
        fread(buf, 1, BUF, stdin), pos = 0;
    return buf[pos++];
}

inline int read()  {
    int x = 0;
    char ch = next();
    while(!isdigit(ch))
        ch = next();
    while(isdigit(ch))
        x = x * 10 + ch - '0', ch = next();
    return x;
}

int q[MAXN], st = 1, dr = 1;

double maxi(double a, double b)  {
    if(a < b)
        return b;
    return a;
}

int main()  {
    freopen("secv3.in", "r", stdin);
    freopen("secv3.out", "w", stdout);
    n = read(), l = read(), u = read();
    for(int i = 1;i <= n;i++)
        c[i] = read(), c[i] += c[i - 1];
    for(int i = 1;i <= n;i++)
        t[i] = read(), t[i] += t[i - 1];
    double ans = 1.0 * c[l] / t[l];
    st = 1, dr = 0;
    for(int i = l;i <= n;i++)  {
        while(st <= dr && q[st] <= i - u)
              st++;
        while(st <= dr && 1LL * (c[i] - c[q[dr] - 1]) * (t[i] - t[i - l]) < 1LL * (c[i] - c[i - l]) * (t[i] - t[q[dr] - 1]))
              dr--;
        q[++dr] = i - l + 1;
        if(ans < 1.0 * (c[i] - c[q[st] - 1]) / (t[i] - t[q[st] - 1]))
            ans = 1.0 * (c[i] - c[q[st] - 1]) / (t[i] - t[q[st] - 1]);
    }
    printf("%.2lf", ans);
    return 0;
}