結果

問題 No.5 数字のブロック
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 01:40:37
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 333 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 36,824 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 22:02:04
合計ジャッジ時間 1,049 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d %d", &L, &N);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:9:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     for(int i=0;i<N;i++){scanf("%d", W+i);}
      |                          ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <algorithm>

int main(){
    int L, N;
    int W[10000];

    scanf("%d %d", &L, &N);
    for(int i=0;i<N;i++){scanf("%d", W+i);}

    std::sort(W, W+N);

    int sum = 0, n = 0;
    for(int i=0;i<N;i++){
        if(sum + W[i] <= L){sum += W[i]; n += 1;}
    }

    printf("%d\n", n);
}
0