I'm solving this problem:
Vanya walks late t night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?
In some test it gives WA expected: ** *'22258199.50000*00', found: '22258200.0000000'
but in some tests where answer is not integer, my code output correct answer. (i.e. it can output double)
when I saw the solution there was "printf("%.10f", maxdist/2.)"
instead "cout << (double)maxdist/2"
questions:
- why doesn't my code work?
- What means the dot at the end of "
maxdist/2.
"? - Why there is no
"&
" before variablemaxdist
?
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
int main(){
int n, l;
cin >> n >> l;
vector<int> v;
for(int i = 0; i < n; i++){
int x;
cin >> x;
v.pb(x);
}
sort(all(v));
int maxdist = 2*max(v[0], l-v[n-1]);
for(int i = 0; i < n-1; i++){
maxdist = max(maxdist, v[i+1] - v[i]);
}
cout << (double)maxdist/2;
}