Cod sursa(job #1831119)

Utilizator pastoradrianPastor Adrian pastoradrian Data 17 decembrie 2016 15:25:30
Problema Secventa 3 Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 1.33 kb
import java.util.Scanner;
import java.io.*;


public class Secv3 {
	static short cost[], time[];
	static int n, L, U, sumTime[], sumCost[];
	static double ratio, max;
	
	public static void main (String [] args) throws IOException{
		
		Scanner input = new Scanner(new File("secv3.in"));
		File fOut = new File("secv3.out");
		FileWriter fwriter= new FileWriter(fOut);
		PrintWriter output = new PrintWriter(fOut);
		
		n = input.nextInt();
		L = input.nextInt();
		U = input.nextInt();
		
		time = new short[n];
		cost = new short[n];
		sumCost = new int[n];
		sumTime = new int[n];
		
		for(int i = 0; i < n; i++)
			cost[i] = input.nextShort();
		
		for(int i = 0; i < n; i++)
			time[i] = input.nextShort();
		
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < U && (i + j) < n; j++)
			{
				sumCost[i] += cost[i + j]; 
				sumTime[i] += time[i + j]; 
			}
			ratio = (double) ((double)sumCost[i] / (double)sumTime[i]);
			if(ratio > max) max = ratio;
		}
		U--;
		
		while(U >= L)
		{
			for(int i = 0; i <= n; i++)
			if((i + U) < n)
			{
				sumCost[i] -= cost[i + U];
				sumTime[i] -= time[i + U];
				ratio = (double) ((double)sumCost[i] / (double)sumTime[i]);
				if(ratio > max) max = ratio;
			}
		
			U--;
		}
		
		output.println(String.format( "%.2f", max ));
		output.close();
	} 
}