結果

問題 No.5 数字のブロック
ユーザー mumucoder
提出日時 2018-10-28 15:26:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 65,120 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 12:40:29
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char *argv[]) {
	int width = 0;
	int number_of_blocks = 0;
	int input_width = 0;
	std::vector<int> block_widths;

	std::cin >> width;
	std::cin >> number_of_blocks;
	while (std::cin >> input_width) {
		block_widths.push_back(input_width);
	}

	std::sort(block_widths.begin(), block_widths.end());

	int available_blocks = 0;
	int current_width = 0;
	for (auto block_width: block_widths) {
		current_width += block_width;
		if (current_width <= width) {
			available_blocks++;
		} else {
			break;
		}
	}
	std::cout << available_blocks << std::endl;

	return 0;
}
0