結果

問題 No.5 数字のブロック
ユーザー dgd1724
提出日時 2016-09-06 19:05:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 482 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 68,112 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 09:15:32
合計ジャッジ時間 1,923 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>

int main(void) {

	//test用
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	int L, N;
	std::cin >> L >> N;
	std::vector<int> W(N);

	for (int i = 0; i < N; i++) {
		std::cin >> W[i];
	}
	std::sort(W.begin(), W.end());

	int max = 0;
	int i = 0;
	while (i < N) {
		max += W[i];
		if (max <= L) {
			i++;
		}
		else {
			break;
		}
	}

	std::cout << i << std::endl;

}
0