結果

問題 No.5 数字のブロック
ユーザー machy
提出日時 2015-06-11 21:55:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 78,432 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 22:52:08
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
typedef long long LL;

int main(){
    int L, N;
    cin >> L >> N;
    vector<int> w(N);
    for(int i = 0; i < N; i++){
        cin >> w[i];
    }
    sort(w.begin(), w.end());
    LL ans = 0;
    LL sum = 0;
    for(int i = 0; i < N; i++){
        if(sum + w[i] > L) break;
        ans++;
        sum += w[i];
    }
    cout << ans << endl;
    return 0;
}
0