結果

問題 No.5 数字のブロック
ユーザー kyuna
提出日時 2019-08-04 11:15:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 352 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 22:49:28
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int l, n; cin >> l >> n;
    vector<int> w(n);
    for (int &wi: w) cin >> wi;
    sort(w.rbegin(), w.rend());
    int sum = 0;
    while (!w.empty() && sum + w.back() <= l) sum += w.back(), w.pop_back();
    cout << n - w.size() << endl;
    return 0;
}
0