Cod sursa(job #2557057)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 25 februarie 2020 14:35:08
Problema Secventa 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

ifstream fin("secv3.in");
ofstream fout("secv3.out");

int n, mi, ma;
double top[30041], bot[30041];

void read(){
	fin >> n >> mi >> ma;
	for(int i = 1; i <= n; ++i){
		fin >> top[i];top[i] += top[i-1];
	}
	for(int i = 1; i <= n; ++i){
		fin >> bot[i];bot[i] += bot[i-1];
	}
}

double frac(int lt, int rt){
	return (top[rt]-top[lt-1]) / (bot[rt]-bot[lt-1]);
}

double maxi = 0;
void solve(){
	int lt = 1;
	for(int rt = mi; rt <= n; ++rt){
		if(rt-lt >= ma){
			lt++;
		}
		double obg = frac(rt-mi+1, rt);
		double ext = frac(lt, rt);
		if(obg > ext){
			lt = rt-mi+1;
			maxi = max(maxi, obg);
		}else{
			maxi = max(maxi, ext);
		}
	}
	fout << setprecision(6) << fixed;
	fout << maxi;
}

int main(){
	read();
	solve();
	return 0;
}