結果

問題 No.5 数字のブロック
ユーザー Rumain831
提出日時 2025-05-03 02:17:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 347 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 77,716 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-03 02:17:15
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(void){
  int l, n; cin >> l >> n;
  vector<int> w(n);
  for(int i=0; i<n; i++) cin >> w[i];
  sort(w.begin(), w.end());
  int now=0, ans=0;
  for(int i=0; i<n; i++){
    if(now+w[i]<=l) now+=w[i], ans++;
    else break;
  }
  cout << ans << endl;
  return 0;
}
0