結果

問題 No.21 平均の差
ユーザー suppy193suppy193
提出日時 2015-06-03 15:24:17
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,193 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 25,976 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-20 18:59:14
合計ジャッジ時間 848 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main(void) {
	int i, j, imax, max, tmp, N, K, n[11], d, m;
	int sum_max, sum_min;
	double ave_max, ave_min, diff_max;
	scanf("%d", &N);
	scanf("%d", &K);
	for(i = 1;i <= N;i++){
		scanf("%d", &n[i]);
	}
	for(i = 1;i <= N - 1;i++){
		max = n[i];
		imax = i;
		for(j = i + 1;j <= N;j++){
			if(n[j] > max){
				max = n[j];
				imax = j;
			}
		}
		tmp = n[i];
		n[i] = n[imax];
		n[imax] = tmp;
	}
/*	
	for(i = 1;i <= N;i++){
		printf("%d ",n[i]);
	}
*/	
	d = N / K + ((N % K != 0)? 1 : 0);
	m = N % K;
	if(m == 0){
		printf("%d\n", n[1] - n[N]);
		return 0;
	}
//	printf("%d\n", d);
	diff_max = 0;
	for(i = 1;i <= d;i++){
		sum_max = 0;
		for(j = 1;j <= i;j++){
//			printf("%d ", n[j]);
			sum_max += n[j];
		}
		ave_max = (double)sum_max / i;
//		printf("\n");
		sum_min = 0;
		for(j = N;j > N - (m - i) - d + 1;j--){
//			printf("%d ", n[j]);
			sum_min += n[j];
		}
		ave_min = (double)sum_min / (m + d - i - 1);
//		printf("\n%f %f %f\n ", ave_max, ave_min, ave_max - ave_min);
		if(diff_max < ave_max - ave_min){
			diff_max = ave_max - ave_min;
		}
	}
	diff_max = (int)diff_max + ((diff_max > (int)diff_max)? 1 : 0);
	printf("%d\n", (int)diff_max);

	return 0;
}
0