結果

問題 No.5 数字のブロック
ユーザー mitsu__new
提出日時 2018-03-02 11:41:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 336 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 59,012 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 12:06:45
合計ジャッジ時間 1,953 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

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

	sort(W,W+N); //Wを昇順に並べる
	
	int i;
	int sum = 0;
	for(i=0; i<N; i++) {
		sum += W[i];
		if(sum > L) break;
	}
	cout << i << endl;

	delete[] W;
	return 0;
}
0