結果

問題 No.5 数字のブロック
ユーザー tempura-sama
提出日時 2016-04-12 11:10:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 62,532 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-04 07:08:35
合計ジャッジ時間 1,595 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

	//list<int> blocks;
	set<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);
		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