Language: C++

use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let (n, k) = input!(usize, usize);
    let x = input!(i64,);

    let z = x
        .iter()
        .enumerate()
        .skip_while(|(_n, v)| v.is_negative())
        .next();
    let z = match z {
        Some(x) => x.0,
        None => n - 1,
    };

    let mut l;
    if z <= k {
        l = 0;
    } else {
        l = z - k;
    }

    let mut time = Vec::new();
    let x: Vec<_> = x.into_iter().map(i64::abs).collect();
    let (lx, rx) = x.split_at(z);
    let mut lx = lx.to_vec();
    let mut rx = rx.to_vec();
    lx.push(0);
    rx.insert(0, 0);
    while l + k <= n && l <= z {
        let r = l + k - z;
        let l_score = lx[l];
        let r_score = rx[r];
        if l < r {
            time.push(2 * l_score + r_score);
        } else {
            time.push(l_score + 2 * r_score);
        }
        l += 1;
    }
    println!("{}", time.iter().min().unwrap());
}


Compiler output:
a.cc:19:37: error: too many decimal points in number
   19 |     ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
      |                                     ^~~~~~~~~
a.cc:20:42: error: too many decimal points in number
   20 |     ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
      |                                          ^~~~~~~~~
a.cc:23:2: error: invalid preprocessing directive #[
   23 | #[allow(dead_code)]
      |  ^
a.cc:27:2: error: invalid preprocessing directive #[
   27 | #[allow(dead_code)]
      |  ^
a.cc:29:6: error: too many decimal points in number
   29 |     (0..times).map(|_| get_value()).collect()
      |      ^~~~~~~~
a.cc:31:2: error: invalid preprocessing directive #[
   31 | #[allow(dead_code)]
      |  ^
a.cc:38:2: error: invalid preprocessing directive #[
   38 | #[allow(dead_code)]
      |  ^
a.cc:40:6: error: too many decimal points in number
   40 |     (0..times).map(|_| get_vector()).collect()
      |      ^~~~~~~~
a.cc:1:1: error: 'use' does not name a type
    1 | use std::io::stdin;
      | ^~~
a.cc:2:1: error: 'fn' does not name a type
    2 | fn get_string() -> String {
      | ^~
a.cc:8:1: error: 'macro_rules' does not name a type
    8 | macro_rules! input {
      | ^~~~~~~~~~~
a.cc:24:1: error: 'fn' does not name a type
   24 | fn get_value<T: std::str::FromStr>() -> T {
      | ^~
a.cc:28:1: error: 'fn' does not name a type
   28 | fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
      | ^~
a.cc:32:1: error: 'fn' does not name a type
   32 | fn get_vector<T: std::str::FromStr>() -> Vec<T> {
      | ^~
a.cc:39:1: error: 'fn' does not name a type
   39 | fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
      | ^~
a.cc:43:1: error: 'fn' does not name a type
   43 | fn main() {
      | ^~