Cod sursa(job #2917655)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 6 august 2022 17:36:54
Problema Secventa 3 Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>
#define L 30005
using namespace std;
ifstream fin("secv3.in");
ofstream fout("secv3.out");
int a[L], b[L];
int main(){
  int n, l, r, i, j, x, lim;
  double mx = 0, q;
  fin >> n >> l >> r;
  for (i = 1; i <= n; i++){
    fin >> x;
    a[i] = a[i - 1] + x;
  }
  for (i = 1; i <= n; i++){
    fin >> x;
    b[i] = b[i - 1] + x;
  }
  for (i = 1; i <= n - l + 1; i++){
    lim = min(n, i + r - 1);
    for (j = i + l - 1; j <= lim; j++){
      q = (double)(a[j] - a[i - 1]) / (b[j] - b[i - 1]);
      if (mx < q)
        mx = q;
    }
  }
  fout << setprecision(4) << mx << "\n";
  return 0;
}