結果

問題 No.156 キャンディー・ボックス
ユーザー stone_725
提出日時 2015-09-06 08:16:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 44,544 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 15:42:33
合計ジャッジ時間 1,284 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type’ {aka ‘long int’} [-Wformat=]
   20 |   printf("%d\n", upper_bound(c.begin(), c.end(), 0) - lower_bound(c.begin(), c.end(), 0));
      |           ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |            |                                        |
      |            int                                      __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}
      |           %ld
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%d", &c[i]);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

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

using namespace std;

int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> c(n);
  for(int i = 0; i < n; i++){
    scanf("%d", &c[i]);
  }
  sort(c.begin(), c.end());
  for(int i = 0; i < n; i++){
    int tmp = c[i];
    c[i] = max(0, c[i] - m);
    m -= tmp;
  }
  printf("%d\n", upper_bound(c.begin(), c.end(), 0) - lower_bound(c.begin(), c.end(), 0));
  return 0;
}
0