Submission #2973465

Source Code Expand

Copy
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn solve(_n:i32, mut a:Vec<i32>) -> i32 {
    a.sort();
    a.reverse();
    let mut alice:i32 = 0;
    let mut bob:i32 = 0;
    for (i, a_i) in a.iter().enumerate() {
        if i % 2 == 0 {
            alice += *a_i;
        } else {
            bob += *a_i;
        } 
    }
    (alice - bob).abs()
}
fn main() {
    let n = read::<i32>();
    let a = read_vec::<i32>();
    println!("{}", solve(n, a));
}

Submission Info

Submission Time
Task ABC088B - Card Game for Two
User naoya_t
Language Rust (1.15.1)
Score 200
Code Size 731 Byte
Status
Exec Time 2 ms
Memory 4352 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_1.txt, sample_2.txt, sample_3.txt
All 200 / 200 in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample_1.txt, sample_2.txt, sample_3.txt
Case Name Status Exec Time Memory
in1.txt 2 ms 4352 KB
in2.txt 2 ms 4352 KB
in3.txt 2 ms 4352 KB
in4.txt 2 ms 4352 KB
in5.txt 2 ms 4352 KB
in6.txt 2 ms 4352 KB
in7.txt 2 ms 4352 KB
in8.txt 2 ms 4352 KB
in9.txt 2 ms 4352 KB
sample_1.txt 2 ms 4352 KB
sample_2.txt 2 ms 4352 KB
sample_3.txt 2 ms 4352 KB