forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat_space_station.cpp
More file actions
59 lines (43 loc) · 795 Bytes
/
flat_space_station.cpp
File metadata and controls
59 lines (43 loc) · 795 Bytes
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
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
a[i] = i;
vector<int> ar;
for(int i=0;i<m;i++)
{
int x;
cin>>x;
ar.push_back(x);
//// a[ar[i]] = ar[i];
}
sort(ar.begin(),ar.end());
//checking
vector<int> store;
int j,k;
int num=0,flag=0;
if(m==n)
cout<<"0";
else{
int clen = ar[0] - 0;
store.push_back(clen);
int mid;
for(int i=0;i<m-1;i++){
clen = ar[i+1] - ar[i] -1;
if(clen%2==0){
mid = clen/2;
}else
mid = (clen+1)/2;
store.push_back(mid);
}
clen = a[n-1] - ar[m-1];
store.push_back(clen) ;
int max = *max_element(store.begin(),store.end());
cout<<max;
}
}