結果

問題 No.5 数字のブロック
コンテスト
ユーザー hayakawa4739
提出日時 2016-06-28 01:46:15
言語 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
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 686 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 251 ms
コンパイル使用メモリ 38,388 KB
最終ジャッジ日時 2026-02-23 21:39:56
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/*
 * main.c
 *
 *  Created on: 2016/06/28
 *      Author: owner
 */

#include<stdio.h>

int main(void) {
	int width, number, tmp, count,x,i,j,y;

	count = 0;

	scanf("%d", &width);
	scanf("%d", &number);

	int haba[number];

	for (x = 0; x < number; x++) {
		scanf("%d", &haba[x]);
	}

	//数値を昇順にソート
	for (i = 0; i < number; ++i) {
		for (j = i + 1; j < number; ++j) {
			if (haba[i] > haba[j]) {
				tmp = haba[i];
				haba[i] = haba[j];
				haba[j] = tmp;
			}
		}
	}

	for (y = 0; y < number; y++) {
		if (width >= 0) {
			width = width - haba[y];
			if (width < 0) {
				break;
			} else {
				count++;
			}
		} else {
			break;
		}
	}

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

}
0