結果

問題 No.156 キャンディー・ボックス
ユーザー kpinkcat
提出日時 2023-08-03 15:27:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 1,058 ms
コンパイル使用メモリ 108,580 KB
最終ジャッジ日時 2025-02-15 21:48:52
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:15: warning: ‘cnt’ may be used uninitialized [-Wmaybe-uninitialized]
   14 |     int n, m, cnt;
      |               ^~~

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    int n, m, cnt;
    cin >> n >> m;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++){
        if (v[i] <= m){
            cnt++;
            m -= v[i];
        } else break;
    }
    cout << cnt << endl;
}
0