結果

問題 No.5 数字のブロック
ユーザー metasequo
提出日時 2015-05-10 22:59:41
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 624 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 21,120 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 22:42:09
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:35:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d %d", &L, &N);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:36:33: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         for(i = 0; i < N; i++)  scanf("%d", &W[i]);
      |                                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

void sort(int *x, int left, int right)
{
	int i, j, pivot, mem;

	i = left;
	j = right;

	pivot = x[(left + right) / 2];

	while (1) {
		while (x[i] < pivot)
			i++;
		while (pivot < x[j])
			j--;
		if (i >= j)
			break;

		mem = x[i];
		x[i] = x[j];
		x[j] = mem;
		i++;
		j--;
	}

	if (left < i - 1)
		sort(x, left, i - 1);
	if (j + 1 <  right)
		sort(x, j + 1, right);
}

int main(){
	int L, N, W[10001], i;
	scanf("%d %d", &L, &N);
	for(i = 0; i < N; i++)	scanf("%d", &W[i]);

	sort(W, 0, N - 1);
	i = 0;
	do{
		L -= W[i];
		i++;
	}while(L - W[i] >= 0 && W[i] != 0);

	printf("%d\n", i);
	return 0;
}
0