結果

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

ソースコード

diff #

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

using namespace std;

int main()
{
	int L, N;
	cin >> L;
	cin >> N;

	vector<int> W;

	int temp;
	for (int i = 0; i < N; i++){
		cin >> temp;
		W.push_back(temp);
	}

	sort(W.begin(), W.end());

	int sum = 0, count = 0;
	for (vector<int>::size_type i = 0; i < W.size(); i++){
		if (sum <= L){
			sum += W[i];
			count++;
			if (sum > L)
				count--;
		}
		else
			break;
	}
	cout << count << endl;
}
0