結果

問題 No.5 数字のブロック
ユーザー alchemin
提出日時 2019-09-11 09:54:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 524 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 75,500 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 16:43:36
合計ジャッジ時間 1,784 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:22:9: warning: 'ct' may be used uninitialized [-Wmaybe-uninitialized]
   22 |     int ct;
      |         ^~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int main() {
    int l, n;
    vector<int> w;
    
    cin >> l >> n >> std::ws;
    
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp >> std::ws;
        w.push_back(tmp);
    }
    
    sort(w.begin(), w.end());
    
    int ct;
    for (int j = 0; j < n; j++) {
        l -= w[j];
        if (l < 0) {
            break;
        } else {
            ct++;
        }
    }
    
    cout << ct << endl;
    
    return 0;
}
0