-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1203E.cpp
More file actions
31 lines (28 loc) · 877 Bytes
/
1203E.cpp
File metadata and controls
31 lines (28 loc) · 877 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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
map<int, int> cnt;
for(int i = 0, t = 0; i < n; i++) {
cin >> t;
cnt[t]++;
}
vector<int> v(150010, 0);
for(auto & elem : cnt) {
if(elem.second >= 3) {
v[elem.first - 1] = v[elem.first] = v[elem.first + 1] = 1;
}
else if(elem.second == 2) {
v[elem.first] = 1;
if(v[elem.first - 1] != 1 && elem.first != 1) v[elem.first - 1] = 1;
else v[elem.first + 1] = 1;
}
else {
if(v[elem.first - 1] != 1 && elem.first != 1) v[elem.first - 1] = 1;
else if(v[elem.first] != 1) v[elem.first] = 1;
else v[elem.first + 1] = 1;
}
}
int ans = accumulate(v.begin() + 1, v.end(), 0);
cout << ans << endl;
}