結果

問題 No.5 数字のブロック
ユーザー 2475057t2475057t
提出日時 2024-10-13 23:08:00
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 277 ms / 5,000 ms
コード長 704 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 23:08:04
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#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