結果

問題 No.21 平均の差
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-08 05:16:47
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 27,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 09:30:59
合計ジャッジ時間 831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int num[15];
int stack[20];
int scnt=0;
int gAve=0;

int compare_int( const void*a, const void*b){
	int ta = *(int*)a;
	int tb = *(int*)b;
	if(ta < tb){
		return -1;
	}else if(ta > tb){
		return 1;
	}
	
	return 0;
}


	
void saiki(int digit, int k){
	int i;
	if(k == 0 && digit == 0){
		int s;
		int tAve;
		int ssum = 0;
		double minAve = 9999999.0;
		double maxAve = 0.0;
		
		for(s=0;s<scnt;s++){
			double ag = 0.0;
			for(i=0;i<stack[s];i++){
				ag = ag + (1.0*num[ssum+i]);
			}
			
			ag = ag/(1.0*stack[s]);
			
			if(minAve > ag ){
				minAve = ag;
			}
			if(maxAve < ag ){
				maxAve = ag;
			}
			
			ssum += stack[s];
		}
		
		tAve = (int)ceil(maxAve-minAve);
		if(gAve < tAve){
			gAve = tAve;
		}
		return;
	}
	
	for(i=1;i<=digit;i++){
		stack[scnt] = i;
		scnt++;
		saiki(digit-i, k-1);
		scnt--;
	}
	
	return;
}

int main(void){
	int i,n,k;
	
	scanf("%d", &n);
	scanf("%d", &k);
	for(i=0;i<n;i++){
		scanf("%d", &num[i]);
	}
	
	qsort(num, n, sizeof(int), compare_int);
	saiki(n,k);
	
	
	printf("%d\n", gAve);
	return 0;
}
0