Submission details
Task:Apple Division
Sender:aalto25a_003
Submission time:2025-09-03 16:54:08 +0300
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0432]: unresolved import `num`
 --> input/code.rs:3:5
  |
3 | use num::abs;
  |     ^^^ help: a similar path exists: `std::num`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.

Code

use std::cmp::min;
use std::io::{self, Read};
use num::abs;

macro_rules! input {
    ($it: expr) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: expr, $T: ty) => {
        $it.next().unwrap().parse::<$T>().unwrap()
    };
}
/*
mod classes;
fn main() {
    // println!("{}", "-".repeat(20));
    classes::c02::task1();
    // println!("{}", "-".repeat(20));
}
// */

fn main() {
    task();
}

#[allow(dead_code)]
fn task() {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf).unwrap();

    let mut it = buf.split_whitespace();

    let n: usize = input!(it);
    let v: Vec<i32> = (0..n).map(|_| input!(it)).collect();
    let sum = v.iter().sum();
    println!("{}", apple_div(&v, sum, 0, 0));
}

fn apple_div(v: &Vec<i32>, sum_1: i32, sum_2: i32, i: usize) -> i32 {
    if i < v.len() {
        let val_1 = apple_div(v, sum_1, sum_2, i+1);
        let curr = v[i];
        let val_2 = apple_div(v, sum_1 - curr, sum_2 + curr, i+1);
        // println!("{} - {}", val_1, val_2);
        min(val_1, val_2)
    } else {
        abs(sum_1-sum_2)
    }
}