結果

問題 No.5 数字のブロック
ユーザー くれちー
提出日時 2016-08-06 10:07:50
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 08:49:03
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:21:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         scanf("%d %d", &l, &n);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:23:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                 scanf("%d", &w[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

// バブルソート
void sort(int arg[], int n) {
	int temp, i, j;

	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j > i; j--) {
			if (arg[j] < arg[j - 1]) {
				temp = arg[j];
				arg[j] = arg[j - 1];
				arg[j - 1] = temp;
			}
		}
	}
}

int main() {
	int l, n, w[10001], wt = 0, i;

	scanf("%d %d", &l, &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}

	sort(w, n);
	for (i = 0; i < n; i++) {
		if (l >= wt + w[i]) wt += w[i];
		else break;
	}

	printf("%d\n", i);

	return 0;
}
0