Skip to content

Commit e65cc59

Browse files
committed
Added 492B - Vanya and Lanterns.cpp
1 parent 8dd4f78 commit e65cc59

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

492B - Vanya and Lanterns.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define ll long long
6+
#define pb push_back
7+
#define ff first
8+
#define ss second
9+
#define mp make_pair
10+
11+
// Code Written By: Vikash Patel
12+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
13+
14+
double max(double a, double b)
15+
{
16+
return a>b?a:b;
17+
}
18+
19+
int main()
20+
{
21+
ios_base::sync_with_stdio(0);
22+
cin.tie(0);
23+
cout.tie(0);
24+
25+
// #ifndef ONLINE_JUDGE
26+
// freopen("input.txt", "r", stdin);
27+
// freopen("/Users/vikash/Desktop/output.txt", "w", stdout);
28+
// #endif
29+
30+
int n, l;
31+
cin>>n>>l;
32+
vector<int> a(n);
33+
for(int i=0; i<n; i++)
34+
{
35+
cin>>a[i];
36+
}
37+
sort(a.begin(), a.end());
38+
double maxi = INT_MIN;
39+
for(int i=1; i<n ; i++)
40+
{
41+
maxi = max(maxi , a[i]-a[i-1]);
42+
}
43+
double ld = a[0];
44+
double rd = l - a[n-1];
45+
if(a[0] != 0 && a[n-1] != l)
46+
{
47+
cout<<fixed<<setprecision(10)<<max(maxi/2.0, max(ld, rd));
48+
}
49+
else if(a[0] != 0)
50+
{
51+
cout<<fixed<<setprecision(10)<<max(maxi/2.0, ld)<<endl;
52+
}
53+
else if(a[n-1] != l)
54+
{
55+
cout<<fixed<<setprecision(10)<<max(maxi/2.0, rd)<<endl;
56+
}
57+
else
58+
{
59+
cout<<fixed<<setprecision(10)<<maxi/2.0<<endl;
60+
}
61+
return 0;
62+
}

0 commit comments

Comments
 (0)