結果

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

ソースコード

diff #

#include <iostream>
#include <set>
using namespace std;
int main()
{
	int max;
	int n;
	cin >> max;
	cin >> n;

	multiset<int> blocks;
	for ( auto i = 0; i < n; i++ ) {
		int x;
		cin >> x;
		blocks.insert(x);
	}

	// maxを超えないブロック数を小さい順から数えればOKなはず
	int count = 0;
	int t = 0;
	for ( auto block : blocks ) {
		if ( t + block > max ) {
			break;
		}
		count++;
		t += block;
	}

	cout << count << endl;
}
0