-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path45.cpp
More file actions
34 lines (31 loc) · 777 Bytes
/
45.cpp
File metadata and controls
34 lines (31 loc) · 777 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool IsContinuous(vector<int> numbers) {
sort(numbers.begin(), numbers.end());
int len = numbers.size(), zero = 0, internal = 0;
if (len == 0)return false;
for (int i = 0; i < len - 1; i++) {
if (numbers[i] == 0) {
zero++;
continue;
}
if (numbers[i] == numbers[i + 1])return false;
internal += (numbers[i + 1] - numbers[i] - 1);
}
if (zero >= internal)return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
vector<int> v;
int n, temp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
v.push_back(temp);
}
cout << IsContinuous(v);
return 0;
}