結果

問題 No.5 数字のブロック
ユーザー nem1
提出日時 2021-06-01 23:54:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 70,560 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-09 00:23:07
合計ジャッジ時間 1,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    //入力
    int l, n;
    cin >> l >> n;
    
    int w[n];
    for(int i=0; i<n; i++){
        cin >> w[i];
    }
    
    //小さい順ソート
    sort(w, w+n);
    
    //合計がL超えるかちょうどになるまで足す
    int sum = 0, count = 0;
    for(int i=0; i<n; i++){
        sum += w[i];
        count++;
        if(sum > l){
            count--;
            break;
        }else if(sum == l){
            break;
        }
    }
    
    cout << count << endl;
    
    return 0;
}
0