Submission #31915627


Source Code Expand

use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::input;

fn main() {
    input! {
        n: usize,
        l: usize,
        a: [usize; n],
    };

    let sum = a.iter().sum::<usize>();
    let mut pq = BinaryHeap::new();
    for a_i in a {
        pq.push(Reverse(a_i));
    }

    if sum < l {
        pq.push(Reverse(l - sum));
    }

    let mut ans = 0_usize;
    loop {
        match (pq.pop(), pq.pop()) {
            (None, None) => unreachable!(),
            (None, Some(_)) => unreachable!(),
            (Some(Reverse(_)), None) => break,
            (Some(Reverse(x)), Some(Reverse(y))) => {
                ans += x + y;
                pq.push(Reverse(x + y));
            }
        }
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task F - Bread
User bouzuya
Language Rust (1.42.0)
Score 500
Code Size 751 Byte
Status AC
Exec Time 66 ms
Memory 7336 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 1968 KiB
example_01.txt AC 3 ms 2032 KiB
hand_00.txt AC 48 ms 7336 KiB
hand_01.txt AC 3 ms 2028 KiB
hand_02.txt AC 38 ms 5680 KiB
hand_03.txt AC 50 ms 6252 KiB
hand_04.txt AC 50 ms 6420 KiB
hand_05.txt AC 53 ms 7148 KiB
random_00.txt AC 57 ms 6520 KiB
random_01.txt AC 61 ms 7072 KiB
random_02.txt AC 63 ms 7156 KiB
random_03.txt AC 61 ms 7136 KiB
random_04.txt AC 61 ms 7108 KiB
random_05.txt AC 56 ms 6392 KiB
random_06.txt AC 62 ms 7072 KiB
random_07.txt AC 61 ms 7132 KiB
random_08.txt AC 58 ms 7156 KiB
random_09.txt AC 60 ms 7120 KiB
random_10.txt AC 56 ms 6376 KiB
random_11.txt AC 65 ms 7136 KiB
random_12.txt AC 61 ms 7148 KiB
random_13.txt AC 61 ms 7276 KiB
random_14.txt AC 62 ms 7120 KiB
random_15.txt AC 57 ms 6244 KiB
random_16.txt AC 62 ms 7128 KiB
random_17.txt AC 66 ms 7152 KiB
random_18.txt AC 61 ms 7108 KiB
random_19.txt AC 61 ms 7148 KiB
random_20.txt AC 57 ms 6464 KiB
random_21.txt AC 64 ms 7200 KiB
random_22.txt AC 63 ms 7144 KiB
random_23.txt AC 61 ms 7048 KiB
random_24.txt AC 60 ms 7164 KiB