結果

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

ソースコード

diff #

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

using namespace std;

int main(void)
{
	int L, N;
	cin >> L;
	cin >> N;
	int t;
	vector<int> vw;
	for(int i = 0; i < N; i++)
	{
		cin >> t;
		if(vw.size() == 0)
			vw.push_back(t);
		else
		{
			vector<int>::iterator it = lower_bound(vw.begin(), vw.end(), t);
			vw.insert(it, t);
		}
	}

	int sum = 0;
	int count = 0;
	vector<int>::iterator it = vw.begin();
	while(1)
	{
		sum += *it;
		if (sum > L || it == vw.end())
			break;
		else
		{
			it++;
			count++;
		}
	}

	cout << count << endl;

	return 0;
}
0