結果

問題 No.5 数字のブロック
ユーザー RCCW
提出日時 2017-01-31 01:00:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 356 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 164,012 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 10:51:34
合計ジャッジ時間 2,106 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
	int l,n;
	cin>>l;
	cin>>n;
	int sum=0;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin>>a[i];
	}
	int count=0;
	sort(a.begin(),a.end());
	for (int j = 0; j < n; ++j) {
		if (sum+a[j]<=l) {
			sum+=a[j];
			count++;
		}else{
			cout<<count<<endl;
			return 0;
		}
	}
	cout<<count<<endl;
}
0