結果

問題 No.5 数字のブロック
ユーザー Mcpu3Mcpu3
提出日時 2018-04-15 19:13:59
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 29,868 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:56:06
合計ジャッジ時間 3,393 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 0 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(void)
{
	int l, n, *w;
	char str[8192], *ch;
	scanf("%d%*c", &l);
	scanf("%d%*c", &n);
	w = malloc(sizeof(int)*n);
	fgets(str, sizeof(str), stdin);
	ch = strtok(str, " \n");
	for (int i = 0; i < n; i++) {
		if (ch == NULL) break;
		else w[i] = atoi(ch);
		ch = strtok(NULL, " \n");
	}
	int tmp;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (w[j] > w[j + 1]) {
				tmp = w[j];
				w[j] = w[j + 1];
				w[j + 1] = tmp;
			}
		}
	}
	int ans = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		sum = sum + w[i];
		if (l < sum) break;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}
0