Submission #31915627


Source Code Expand

Copy
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));
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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 KB

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 KB
example_01.txt AC 3 ms 2032 KB
hand_00.txt AC 48 ms 7336 KB
hand_01.txt AC 3 ms 2028 KB
hand_02.txt AC 38 ms 5680 KB
hand_03.txt AC 50 ms 6252 KB
hand_04.txt AC 50 ms 6420 KB
hand_05.txt AC 53 ms 7148 KB
random_00.txt AC 57 ms 6520 KB
random_01.txt AC 61 ms 7072 KB
random_02.txt AC 63 ms 7156 KB
random_03.txt AC 61 ms 7136 KB
random_04.txt AC 61 ms 7108 KB
random_05.txt AC 56 ms 6392 KB
random_06.txt AC 62 ms 7072 KB
random_07.txt AC 61 ms 7132 KB
random_08.txt AC 58 ms 7156 KB
random_09.txt AC 60 ms 7120 KB
random_10.txt AC 56 ms 6376 KB
random_11.txt AC 65 ms 7136 KB
random_12.txt AC 61 ms 7148 KB
random_13.txt AC 61 ms 7276 KB
random_14.txt AC 62 ms 7120 KB
random_15.txt AC 57 ms 6244 KB
random_16.txt AC 62 ms 7128 KB
random_17.txt AC 66 ms 7152 KB
random_18.txt AC 61 ms 7108 KB
random_19.txt AC 61 ms 7148 KB
random_20.txt AC 57 ms 6464 KB
random_21.txt AC 64 ms 7200 KB
random_22.txt AC 63 ms 7144 KB
random_23.txt AC 61 ms 7048 KB
random_24.txt AC 60 ms 7164 KB


2025-04-11 (Fri)
17:41:40 +00:00