CSES - Datatähti 2015 loppu - Results
Submission details
Task:Pörssihai
Sender:fergusq
Submission time:2015-01-29 14:03:33 +0200
Language:Java
Status:BUSTED

Code

public class Pörssi {

	static double keskiarvo(int a, int l, int[] arr) {
		int koko = l-a+1;
		double summa = 0;
		for (int i = a; i <= l; i++) {
			summa += arr[i];
		}
		return summa/(double)koko;
	}
	
	public static void main(String[] args) {
		IO io = new IO();
		
		int n = io.nextInt();
		int[] a = new int[n], v = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = io.nextInt();
			double mka = 0;
			int mkai = 0;
			for (int j = 0; j <= i; j++) {
				double ka = keskiarvo(i-j, i, a);
				//System.out.println(i + ":" + j + " " + ka);
				if (mka <= ka) {
					mka = ka;
					mkai = j+1;
				}
			}
			v[i] = mkai;
		}
		
		for (int i = 0; i < n; i++) io.print(v[i] + " ");
		
		io.close();
	}
	
}