結果

問題 No.21 平均の差
ユーザー めうめう🎒めうめう🎒
提出日時 2016-05-08 20:45:14
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,716 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 61,748 KB
最終ジャッジ日時 2024-04-15 13:56:30
合計ジャッジ時間 9,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
47,172 KB
testcase_01 AC 182 ms
41,852 KB
testcase_02 AC 179 ms
41,952 KB
testcase_03 AC 140 ms
41,504 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	private int[] sum;
	private int[] how;
	private int[] num;
	private int n;
	private int k;
	
	Main(){
		sum = new int[10];
		how = new int[10];
		num = new int[10];
	}
	
	//セッター
	public void setN(int n){
		this.n = n;
	}
	
	public void setNum(int i,int a){
		this.num[i] = a;
	}
	
	public void setK(int k){
		this.k = k;
	}
	
	public void plusSum(int i,int num){
		this.sum[i] += num;
	}
	
	//ゲッター
	public int getN(){
		return this.n;
	}
	
	public int getK(){
		return this.k;
	}
	
	public int getNum(int now){
		return this.num[now];
	}
	
	public int getSum(int now){
		return this.sum[now];
	}
	
	public int getHow(int now){
		return this.how[now];
	}
	
	//再帰
	public int run(){
		double re = this.saiki(0);
		return (int) Math.ceil(re);
	}
	
	private double saiki(int now){
		if(now == getN()){
			double max_h = 0.0,min_h = 100000000.0;
			boolean flag = false;
			for(int i = 0;i < getK();i++){
				if(getSum(i) == 0) flag = true;
				double S = (double) getSum(i);
				double H = (double) getHow(i);
				max_h = Math.max(max_h, S / H);
				min_h = Math.min(min_h, S / H);
			}
			if(flag) return 0.0;
			return max_h - min_h;
		}
		double max_n = 0.0;
		for(int i = 0;i < getK();i++){
			plusSum(i, getNum(now));
			this.how[i]++;
			max_n = Math.max(saiki(now + 1),max_n);
			plusSum(i, -getNum(now));
			this.how[i]--;
		}
		return max_n;
	}
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main();
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a;
		m.setN(n);
		m.setK(k);
		for(int i = 0;i < n;i++){
			a = sc.nextInt();
			m.setNum(i, a);
		}
		System.out.println(m.run());
	}
}
0