結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー 友利奈緒
提出日時 2015-03-21 14:21:07
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 939 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,114 ms
コンパイル使用メモリ 183,384 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-18 07:30:29
合計ジャッジ時間 1,937 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 9 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:5: warning: 'm' may be used uninitialized [-Wmaybe-uninitialized]
   30 |     if(c[i]<m) m-=c[i];
      |     ^~
main.cpp:24:9: note: 'm' was declared here
   24 |   int n,m;
      |         ^

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main(){
  int n,m;
  cin >> n,m;
  vi c(n);
  rep(i,n) cin >> c[i];
  sort(all(c));
  rep(i,n){
    if(c[i]<m) m-=c[i];
    else if(c[i]==m){
      cout << i+1 << endl;
      return 0;
    }
    else{
      cout << i << endl;
      return 0;
    }
  }
  cout << n << endl;
}
0