結果

問題 No.5 数字のブロック
ユーザー tokkaka
提出日時 2016-07-16 22:22:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 89,160 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 08:46:08
合計ジャッジ時間 1,611 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>

using namespace std;

int main()
{
    int L, N;
    cin >> L >> N;
    vector<int> W(N);
    for(auto &w : W) cin >> w;
    std::sort(W.begin(), W.end());
    int count = 0;
    int total = 0;
    while(count < N) {
        if(total + W[count] <= L) {
            total += W[count];
            count++;
        } else {
            break;
        }
    }
    cout << count << endl;
}
0