結果

問題 No.156 キャンディー・ボックス
ユーザー 👑 CleyL
提出日時 2020-01-07 23:19:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 74,444 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-23 01:20:57
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    for(int i = 0; n > i; i++){
        cin>>a[i];
    }
    int ans = 0;
    sort(a.begin(),a.end());
    for(int i = 0; 1; i++){
        if(m >= a[i]){
            ans++;
            m -= a[i];
            a[i] = 0;
        }else{
            m = 0;
        }
        if(!m){
            cout << ans << endl;
            return 0;
            
        }
    }
    
}
0