結果

問題 No.5 数字のブロック
ユーザー nanatutmcnanatutmc
提出日時 2019-09-20 01:06:16
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 734 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-22 10:08:10
合計ジャッジ時間 3,599 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 RE * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:3:1: warning: return type defaults to 'int' [-Wimplicit-int]
    3 | main() {
      | ^~~~
main.c: In function 'main':
main.c:34:13: warning: 'return' with no value, in function returning non-void
   34 |             return;
      |             ^~~~~~
main.c:3:1: note: declared here
    3 | main() {
      | ^~~~

ソースコード

diff #

#include <stdio.h>

main() {
    int L, N;
    int width[10000];
    scanf("%d", &L);
    scanf("%d", &N);
    
    for (int i=0; i<N; i++) {
        scanf("%d", &(width[i]));
    }
    
    // sort
    while (1) {
        int flag = 0;
        for (int i=0; i<N-1; i++) {
            if (width[i] > width[i+1]) {
                int tmp = width[i];
            
                width[i] = width[i+1];
                width[i+1] = tmp;
                flag = 1;
            }
        }
        if (flag == 0)
            break;
    }
    
    int total = 0;
    for (int i = 0; i<N; i++) {
        total += width[i];
        if (total > L) {
            printf("%d\n", i);
            return;
        }
    }
    printf("%d\n", N);
}
0