AC043 in rust, finished all. (D doesn't get tested correctly locally)

This commit is contained in:
2022-05-28 14:58:05 +02:00
parent b378c4cb07
commit 97ee8adbf3
6 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
use proconio::input;
fn cost(target: i32, numbers: &[i32]) -> i32 {
let mut result = 0;
for n in numbers {
result += (target - n) * (target - n)
}
result
}
fn main() {
input!{
n: i32,
a: [i32; n],
};
let mut min = std::i32::MAX;
for t in -100..=100 {
let r = cost(t, &a);
if r < min {
min = r;
}
}
println!("{}", {min});
}