結果

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

ソースコード

diff #

#include <stdio.h>
int main(void){
    int L,N,W[10000],tmp,h;
    scanf("%d%d",&L,&N);
    for(int i=0;i<N;i++){
        scanf("%d",&W[i]);
    }
    for (int i=0; i<N-1; i++) {
        for (int j=i; j<N; j++) {
            if(W[i]>W[j]){
                tmp=W[i];
                W[i]=W[j];
                W[j]=tmp;
            }
        }
    }
    for(h=0;h<N;h++){
        L-=W[h];
        if(L<0){
            break;
        }
        else if(L==0){
            h++;
            break;
        }
    }
    printf("%d\n",h);
    
    return 0;
}
0