結果

問題 No.5 数字のブロック
ユーザー rsk0315
提出日時 2020-03-15 21:43:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 357 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 58,120 KB
最終ジャッジ日時 2025-01-09 07:08:49
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d %zu", &l, &n);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:11:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   for (auto& wi: w) scanf("%d", &wi);
      |                     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  int l;
  size_t n;
  scanf("%d %zu", &l, &n);

  std::vector<int> w(n);
  for (auto& wi: w) scanf("%d", &wi);
  std::sort(w.begin(), w.end());

  int acc = 0;
  for (size_t i = 0; i < n; ++i) {
    acc += w[i];
    if (acc > l) return !printf("%zu\n", i);
  }
  printf("%zu\n", n);
}
0