fn main() { let v1 = input_line_vc::(); let mut a = input_line_vc::(); a.sort(); a.reverse(); let mut result = 0; if a[0] < 0 { println!("{}", a[0]); return; } for i in 0..v1[1] { if a[i] >= 0 { result += a[i]; } } println!("{}", result); } fn input_line_vc() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }