Skip to content

Instantly share code, notes, and snippets.

@MasterAlish
Created January 4, 2014 10:38
Show Gist options
  • Save MasterAlish/8254035 to your computer and use it in GitHub Desktop.
Save MasterAlish/8254035 to your computer and use it in GitHub Desktop.
olymp.krsu.147
import java.util.Scanner;
public class Solution {
public static void main(String[] arg){
int N, M;
int[] A;
Scanner in = new Scanner(System.in);
N = in.nextInt();
M = in.nextInt();
A = new int[N];
for(int i=0;i<N;i++)
A[i]= in.nextInt();
Solution try2 = new Solution(N, M, A);
String result = String.format("%.3f",try2.solve()).replace(',','.');
System.out.printf(result);
}
int tires;
int wheels;
int[] runOut;
public Solution(int wheels, int tires, int ... runOut){
this.tires = tires;
this.wheels = wheels;
this.runOut = runOut;
}
public double solve(){
double maxRunOut = getMaxRunOut();
double sumOfRunOutRatios = getSumOfRunOutRatios(maxRunOut);
return (maxRunOut*tires)/sumOfRunOutRatios;
}
private int getMaxRunOut() {
int max = runOut[0];
for(int x:runOut){
if(x>max){
max = x;
}
}
return max;
}
private double getSumOfRunOutRatios(double maxRunOut) {
double sum = 0;
for(int singleRunOut:runOut)
sum += maxRunOut/(double)singleRunOut;
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment