結果

問題 No.5 数字のブロック
ユーザー xvfz57
提出日時 2019-10-27 00:02:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 405 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 65,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 20:58:08
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:11: warning: ‘count’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |   cout << count << endl;
      |           ^~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main(){
  int l, n, i, w, count;
  vector<int> w_v;
  cin >> l >> n;
  for (i = 0;i<n;i++){
    cin >> w;
    w_v.push_back(w);
  }
  sort(w_v.begin(),w_v.end());
  i = 0;
  while(true){
    if (w_v[i] > l){
      break;
    }
    l = l - w_v[i];
    count++;
    i++;
  }
  cout << count << endl;
}
0