結果

問題 No.5 数字のブロック
コンテスト
ユーザー ksbaseball
提出日時 2021-04-03 17:17:35
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 472 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,597 ms
コンパイル使用メモリ 174,636 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-30 20:01:13
合計ジャッジ時間 2,927 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
    8 |     int b[block];
      |           ^~~~~
main.cpp:8:11: note: read of non-const variable 'block' is not allowed in a constant expression
main.cpp:6:14: note: declared here
    6 |     int box, block;
      |              ^
1 warning generated.

ソースコード

diff #
raw source code

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

int main()
{
    int box, block;
    cin >> box; cin >> block;
    int b[block];
    for(int i = 0; i < block; i++){
        cin >> b[i];
    }
    
    int total = 0;
    int output = 0;
    
    sort(b, b + block);

    while(total <= box){
        total += b[output];
        output += 1; 
    }
    if(total <= box){
        cout << output << endl;
    }
    else{
        cout << output-1 << endl;
    }
    return 0;
}
0