結果

問題 No.5 数字のブロック
コンテスト
ユーザー Mcpu3
提出日時 2018-04-15 19:08:02
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 706 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 238 ms
コンパイル使用メモリ 39,616 KB
最終ジャッジ日時 2026-02-22 00:59:55
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(void)
{
	int l, n, *w;
	char str[32], *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