結果

問題 No.5 数字のブロック
ユーザー jdksk31
提出日時 2023-04-28 19:53:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 380 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 197,880 KB
最終ジャッジ日時 2025-02-12 14:43:51
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define debug if(0)

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int l, n; cin>>l>>n;
	vector<int> w(n);
	for(int &x : w) cin>>x;
	sort(w.begin(), w.end());
	int sum = 0, ans = 0;
	for(int i=0; i<n; i++) {
		if((sum+w[i]) > l) break;
		else {
			sum += w[i];
			ans++;
		}
	}
	cout<<ans<<"\n";
}
0