結果

問題 No.5 数字のブロック
ユーザー drymousedrymouse
提出日時 2019-12-12 23:04:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 1,056 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 29,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 03:53:08
合計ジャッジ時間 3,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 76 ms
4,380 KB
testcase_04 AC 55 ms
4,380 KB
testcase_05 AC 117 ms
4,376 KB
testcase_06 AC 58 ms
4,376 KB
testcase_07 AC 44 ms
4,380 KB
testcase_08 AC 70 ms
4,376 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 131 ms
4,380 KB
testcase_11 AC 38 ms
4,380 KB
testcase_12 AC 78 ms
4,376 KB
testcase_13 AC 110 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 120 ms
4,380 KB
testcase_17 AC 156 ms
4,376 KB
testcase_18 AC 141 ms
4,380 KB
testcase_19 AC 169 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 0 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 52 ms
4,380 KB
testcase_30 AC 21 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort(int *x, size_t s);

void swap(int *a, int *b);

int main(void) {
    int L, N;
    int W[10000] = {0};
    int *pW;
    int sW;
    pW = W;
    sW =  sizeof(W) / sizeof(W[0]);

    scanf("%d", &L);
    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        scanf("%d", &W[i]);
    }
    
    sort(pW, sW);
    
    int sum = 0;
    int Nmax = N;
    for (int i = 0; i < sW; i++) {
        if (W[i] == 0) {
            Nmax = i;
            break;
        }
        sum += W[i];
        if (sum > L) {
            Nmax = i;
            break;
        }
    }

    printf("%d\n", Nmax);
    return EXIT_SUCCESS;
}

void sort(int *x, size_t s) {
    for (int i = s; i > 1; i--) {
        for (int j = 1; j < i; j++) {
            if (*(x+j) == 0) {
                break;
            } else if (*(x+j-1) > *(x+j)) {
                swap(x+j-1, x+j);
            }
        }
    }
    return;
}

void swap(int *a, int *b) {
    int t;
    t = *a;
    *a = *b;
    *b = t;
    return;
}
0