結果

問題 No.5 数字のブロック
ユーザー tempura-samatempura-sama
提出日時 2016-04-12 10:25:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 170 ms / 5,000 ms
コード長 718 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 67,140 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 08:29:23
合計ジャッジ時間 2,759 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

	// 入力されるブロックを小さい順に並べ替えながら、blocksに入れていく
	list<int> blocks;
	for ( auto i = 0; i < n; i++ ) {
		int x;
		cin >> x;
		list<int>::iterator it;
		for ( it = blocks.begin(); it != blocks.end() && *it < x; ++it ) {
			// itを取得したいだけなので何もしない
		}
		blocks.insert(it, x);
	}

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

	cout << count << endl;

	return 0;
}
0