結果

問題 No.5 数字のブロック
ユーザー pinikypiniky
提出日時 2015-09-02 14:57:13
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 362 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 59,900 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 07:33:19
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main(){
	int L, N, nowL = 0, W[10001];
	cin >> L >> N;
	for (int i = 0; i < N; i++) cin >> W[i];

	sort(W, W+N);
	
	for (int i = 0; i < N; i++){
		if ((nowL + W[i]) <= L){
			nowL += W[i];
		}
		else{
			cout << i << endl;
			return 0;
		}
	}
	cout << N << endl;

	return 0;
}
0