結果

問題 No.5 数字のブロック
コンテスト
ユーザー nanatutmc
提出日時 2019-09-20 01:06:50
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 143 ms
コンパイル使用メモリ 27,460 KB
最終ジャッジ日時 2026-02-22 04:43:52
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c:3:1: error: return type defaults to 'int' [-Wimplicit-int]
    3 | main() {
      | ^~~~

ソースコード

diff #
raw source code

#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 0;
        }
    }
    printf("%d\n", N);
}
0