結果

問題 No.156 キャンディー・ボックス
ユーザー m0ntBL4Ncm0ntBL4Nc
提出日時 2019-10-10 13:40:24
言語 Rust
(1.72.1)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 145,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 12:11:01
合計ジャッジ時間 4,062 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let mut number_of_empty_candy_box = 0;

    let line = getline();
    let params: Vec<_> = line.trim().split(' ').collect();
    let number_of_candy_box: usize = params[0].parse().unwrap();
    let number_of_pick_candy: usize = params[1].parse().unwrap();

    let line = getline();
    let params: Vec<_> = line.trim().split(' ').collect();
    let mut candy_boxes: Vec<i32> = Vec::new();

    for i in 0..number_of_candy_box {
        let number_of_candy: i32 = params[i].parse().unwrap();
        candy_boxes.push(number_of_candy);
    }


    for _ in 0..number_of_pick_candy {
        let mut min = 1000000;
        let mut min_candy_box_index: usize = 0;

        for i in 0..number_of_candy_box {
            if candy_boxes[i] == 0 {
                continue;
            }
            if candy_boxes[i] <= min {
                min = candy_boxes[i];
                min_candy_box_index = i;
            }
        }

        if candy_boxes[min_candy_box_index] - 1 >= 0 {
            candy_boxes[min_candy_box_index] -= 1;
            if candy_boxes[min_candy_box_index] == 0 {
                number_of_empty_candy_box += 1;
            }
        }
    }

    println!("{}", number_of_empty_candy_box);
}
0