-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0042.cpp
More file actions
34 lines (30 loc) · 792 Bytes
/
E0042.cpp
File metadata and controls
34 lines (30 loc) · 792 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
/*
Problem Statement: https://www.hackerrank.com/challenges/flatland-space-stations/problem
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int flatlandSpaceStations(int n, vector<int> c) {
vector<int> lengths;
sort(c.begin(), c.end());
lengths.push_back(c[0]);
for(int i=1 ; i<c.size() ; i++)
lengths.push_back(c[i]- c[i-1] - 1);
lengths.push_back(n-c[c.size()-1] - 1);
int max = (*max_element(lengths.begin()+1, lengths.end()) + 1)/2;
int special = (lengths[0] > lengths[lengths.size()-1]) ? lengths[0] : lengths[lengths.size()-1];
return (max > special) ? max : special;
}
int main()
{
int n, m, num;
vector<int> c;
cin>>n>>m;
for(int i=0 ; i<m ; i++){
cin>>num;
c.push_back(num);
}
cout<<flatlandSpaceStations(n, c);
return 0;
}