結果

問題 No.156 キャンディー・ボックス
ユーザー カルロスカルロス
提出日時 2015-09-07 16:39:51
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 24,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 02:59:10
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 0 ms
4,380 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 0 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 0 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 0 ms
4,380 KB
testcase_32 AC 0 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void Quicksort(int data[], int left, int right){
    int l = left, r = right;
    int pivot = data[(left + right) / 2];
    int temp;

    while(1){
        while (data[l] < pivot) l++;
        while (pivot < data[r]) r--;
        if(r < l) break;

        temp = data[l];
        data[l] = data[r];
        data[r] = temp;

        l++, r--;
    }
    if(left < r)  Quicksort(data, left, r);
    if(l < right) Quicksort(data, l, right);
}

int main(void){
    int i, N, M, ans = 0;
    scanf("%d %d", &N, &M);
    int c[N];
    for (i=0;i<N;i++) scanf("%d", &c[i]);
    Quicksort(c, 0, N-1);
    i = 0;
    while(M>0 && i<N){
        if(c[i]>M){
            M = 0;
        }else{
            M -= c[i];
            ans++;
        }
        i++;
    }
    printf("%d\n", ans);
    return 0;
}
0