-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1283E.cpp
More file actions
executable file
·45 lines (38 loc) · 848 Bytes
/
Copy path1283E.cpp
File metadata and controls
executable file
·45 lines (38 loc) · 848 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
// Problem Code: 1283E
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void parties(int n, vector<int>& x) {
int min_h, max_h;
vector<bool> taken(n + 2);
sort(x.begin(), x.end());
// Minimum calculation
for (int i = 0; i < n; i++) {
if (taken[x[i] - 1] || taken[x[i]])
continue;
taken[x[i] + 1] = true;
}
min_h = count(taken.begin(), taken.end(), true);
// Maximum calculation
fill(taken.begin(), taken.end(), false);
for (int i = 0; i < n; i++) {
if (!taken[x[i] - 1])
taken[x[i] - 1] = true;
else if (!taken[x[i]])
taken[x[i]] = true;
else
taken[x[i] + 1] = true;
}
max_h = count(taken.begin(), taken.end(), true);
cout << min_h << " " << max_h;
}
int main() {
int n;
cin >> n;
vector<int> x(n);
for (int i = 0; i < n; i++)
cin >> x[i];
parties(n, x);
return 0;
}