forked from Vicfred/codeforces-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanya_and_lanterns_492B.rs
56 lines (43 loc) · 1.15 KB
/
vanya_and_lanterns_492B.rs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// https://codeforces.com/problemset/problem/492/B
// greedy, sorting
use std::io;
fn check(lanterns: &Vec<i64>, l: i64) -> f64 {
let mut current = 0;
let mut maxima: f64 = f64::abs(lanterns[0] as f64);
for lantern in lanterns {
let distance: f64 = f64::abs((current-*lantern) as f64);
if distance/2.0 > maxima {
maxima = distance/2.0;
}
current = *lantern;
}
let distance: f64 = f64::abs((current-l) as f64);
if distance > maxima {
maxima = distance;
}
return maxima;
}
fn main() {
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.unwrap();
let words: Vec<i64> =
line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let _n = words[0];
let l = words[1];
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.unwrap();
let mut a: Vec<i64> =
line
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
a.sort();
println!("{}", check(&a, l));
}