結果

問題 No.5 数字のブロック
ユーザー youjo_yamioti
提出日時 2018-11-30 10:00:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 378 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 36,968 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 12:43:30
合計ジャッジ時間 1,157 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d %d",&L,&N);
      |     ~~~~~^~~~~~~~~~~~~~~
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d",&W[i]);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<algorithm>

int main(){
    int W[10000];
    int L,N,i;
    int max = 0;
    int sum = 0;
    scanf("%d %d",&L,&N);
    for(i = 0; i < N; i++){
        scanf("%d",&W[i]);
    }
    std::sort(W,W + N);
    for(i=0;i<N;i++){
        sum += W[i];
        if(sum <= L){
            max++;
        }else break;
    }
    printf("%d\n",max);
    return 0;
}
0