fn main() {
let mut lines = std::io::stdin().lines();
let (n, k) = {
let nk = lines
.next()
.unwrap()
.unwrap()
.split_whitespace()
.map(|x| str::parse(x).unwrap())
.collect::<Vec<i32>>();
(nk[0], nk[1])
};
let a = lines
.next()
.unwrap()
.unwrap()
.split_whitespace()
.map(|x| str::parse(x).unwrap())
.collect::<Vec<i32>>();
let mut total = 0;
for i in 0..n {
let mut target = i32::MIN;
for j in 0..n {
target = target.max(a[j as usize] - (i - j).abs() * k);
}
total += target - a[i as usize];
}
println!("{}", total);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | fn main() { let mut lines = std::io::stdin().lines(); let (n, k) = { let nk = lines .next() .unwrap() .unwrap() .split_whitespace() .map(|x| str::parse(x).unwrap()) .collect::<Vec<i32>>(); (nk[0], nk[1]) }; let a = lines .next() .unwrap() .unwrap() .split_whitespace() .map(|x| str::parse(x).unwrap()) .collect::<Vec<i32>>(); let mut total = 0; for i in 0..n { let mut target = i32::MIN; for j in 0..n { target = target.max(a[j as usize] - (i - j).abs() * k); } total += target - a[i as usize]; } println!("{}", total); } |
English