結果

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

ソースコード

diff #

#include <iostream>
#include <set>
using namespace std;
int main()
{
	cin.tie(0);

	int max;
	int n;
	cin >> max;
	cin >> n;

	// setだと速度どうなるんだろうか
	set<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;

	return 0;
}
0