Cod sursa(job #2148906)

Utilizator grecubogdanGrecu Bogdan grecubogdan Data 2 martie 2018 09:43:07
Problema Secventa 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iomanip>
#include <fstream>
using namespace std;
ifstream f("secv3.in");
ofstream g("secv3.out");
const int NMAX = 30000;
int n, l, u;
int temp[1 + NMAX];
int cost[1 + NMAX];
double r1, r2;
int main()
{
  in >> n >> l >> u;
  for(int i = 1; i <= n; i++) {
    in >> cost[i];
    cost[i] += cost[i - 1];
  }
  for(int i = 1; i <= n; i++) {
    in >> temp[i];
    temp[i] += temp[i - 1];
  }
  double res = 1.0L * cost[l] / temp[l];
  int i, j;
  j = 1;
  for(i = l + 1; i <= n; i++) {
    if(i == u + l)
      j++;
    r1 = 1.0L * (cost[i] - cost[j - 1]) / (1.0L * (temp[i] - temp[j - 1]));
    r2 = 1.0L * (cost[i] - cost[i - l]) / (1.0L * (temp[i] - temp[i - l]));

    if(r1 < r2) {
      r1 = r2;
      j = i - l + 1;
    }
    res = max(res, r1);
  }
  out << setprecision(3) << fixed;
  out << res << '\n';
  return 0;
}