ABC 048, finished all with help of editorial
This commit is contained in:
25
atcoder/beginner_contests/abc048/src/bin/c.rs
Normal file
25
atcoder/beginner_contests/abc048/src/bin/c.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main(){
|
||||
input!{
|
||||
n: u64,
|
||||
x: u64,
|
||||
mut a: [u64; n],
|
||||
};
|
||||
|
||||
let mut result = 0;
|
||||
for i in 0..=((n-2) as usize) {
|
||||
if a[i] + a[i+1] > x {
|
||||
let dif = a[i] + a[i+1] - x;
|
||||
if dif > a[i+1] {
|
||||
a[i] -= dif - a[i+1];
|
||||
a[i+1] = 0;
|
||||
} else {
|
||||
a[i+1] -= dif;
|
||||
}
|
||||
result += dif;
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", result);
|
||||
}
|
||||
Reference in New Issue
Block a user