結果

問題 No.5 数字のブロック
ユーザー marinebox
提出日時 2020-11-13 05:02:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 417 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 170,956 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 19:52:09
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int l, n;
    cin >> l >> n;
    vector<int> w(n);
    for(auto &i : w) cin >> i;

    sort(w.begin(), w.end());
    
    int ans = 0;
    int length = 0;
    for(int i = 0; i < n; i++){
        length += w[i];
        if(length > l){
            break;
        }
        else{
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}
0