Submission #37753501


Source Code Expand

Copy
use proconio::input;
fn main() {
input! {
n: usize,
k: usize,
x: [i64; n],
};
let mut minus = vec![];
let mut zero = vec![];
let mut plus = vec![];
for x_i in x.iter().copied() {
match x_i.cmp(&0) {
std::cmp::Ordering::Less => minus.push(x_i),
std::cmp::Ordering::Equal => zero.push(x_i),
std::cmp::Ordering::Greater => plus.push(x_i),
}
}
minus.reverse();
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        x: [i64; n],
    };

    let mut minus = vec![];
    let mut zero = vec![];
    let mut plus = vec![];
    for x_i in x.iter().copied() {
        match x_i.cmp(&0) {
            std::cmp::Ordering::Less => minus.push(x_i),
            std::cmp::Ordering::Equal => zero.push(x_i),
            std::cmp::Ordering::Greater => plus.push(x_i),
        }
    }
    minus.reverse();

    let k = if zero.is_empty() { k } else { k - 1 };

    if k == 0 {
        println!("0");
        return;
    }

    let mut ans = 1 << 60;
    for cm in 0..=k {
        if cm > minus.len() {
            continue;
        }
        let cp = k - cm;
        if cp > plus.len() {
            continue;
        }
        let d_minus = if cm == 0 { 0 } else { minus[cm - 1].abs() };
        let d_plus = if cp == 0 { 0 } else { plus[cp - 1] };
        ans = ans.min(d_minus * 2 + d_plus).min(d_minus + d_plus * 2);
    }

    println!("{}", ans);
}

Submission Info

Submission Time
Task C - Candles
User bouzuya
Language Rust (1.42.0)
Score 300
Code Size 1016 Byte
Status AC
Exec Time 15 ms
Memory 4644 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 12
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt AC 5 ms 2148 KB
0_01.txt AC 1 ms 2056 KB
0_02.txt AC 1 ms 2116 KB
0_03.txt AC 1 ms 1988 KB
1_00.txt AC 13 ms 4328 KB
1_01.txt AC 12 ms 4412 KB
1_02.txt AC 15 ms 4644 KB
1_03.txt AC 11 ms 4588 KB
1_04.txt AC 14 ms 4584 KB
1_05.txt AC 11 ms 4508 KB
1_06.txt AC 10 ms 4600 KB
1_07.txt AC 10 ms 4620 KB


2025-04-08 (Tue)
07:54:49 +00:00