結果

問題 No.5 数字のブロック
コンテスト
ユーザー 2475057t
提出日時 2024-10-13 23:08:00
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 704 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 217 ms
コンパイル使用メモリ 39,360 KB
最終ジャッジ日時 2026-02-22 12:02:29
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

void sort(int array[], int n){
    
    for(int i=0; i<n; i++){
        for(int j=n-1; j>i; j--){
            if(array[j] < array[j-1]){
                int tmp = array[j];
                array[j] = array[j-1];
                array[j-1] = tmp;
            }
        }
    }
    
    return;
}

int main()
{
    int L, N;
    scanf("%d", &L);
    scanf("%d", &N);
    int W[N];
    for(int i=0; i<N; i++){
        scanf("%d", &W[i]);
    }
    
    sort(W, N);
    
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (L >= W[i]) {
            L -= W[i];
            cnt++;
        } else {
            break;
        }
    }
    
    printf("%d\n", cnt);

    return 0;
}
0