結果

問題 No.5 数字のブロック
ユーザー oooooba
提出日時 2021-01-07 22:33:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 489 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 79,336 KB
最終ジャッジ日時 2025-01-17 10:27:06
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <optional>
#include <vector>

using namespace std;

int main() {
    int32_t l, n;
    cin >> l >> n;
    vector<int32_t> ws(n);
    for (auto i = 0; i < n; ++i) {
        cin >> ws[i];
    }
    sort(ws.begin(), ws.end());
    int32_t ans = 0, sum = 0;
    for (auto w : ws) {
        if (sum + w > l)
            break;
        ++ans;
        sum += w;
    }
    cout << ans << endl;
    return 0;
}
0