結果

問題 No.5 数字のブロック
ユーザー Mcpu3
提出日時 2018-04-15 19:13:59
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-27 00:04:54
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 17
権限があれば一括ダウンロードができます

ソースコード

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