結果

問題 No.5 数字のブロック
ユーザー shiratama
提出日時 2016-08-07 21:36:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 492 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 64,408 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 08:49:56
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

auto main() -> int {
	int l;
	int n;
	std::cin >> l;
	std::cin >> n;

	std::vector<int> ws(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> ws[i];
	}

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

	int last_i = 0;
	int total_width = 0;
	for (last_i = 0; last_i < n; ++last_i) {
		total_width += ws[last_i];
		if (total_width == l) {
			last_i++;
			break;
		} else if (total_width > l) {
			break;
		}
	}

	std::cout << last_i << std::endl;
}
0