-
Notifications
You must be signed in to change notification settings - Fork 0
/
counting-liars.cpp
59 lines (46 loc) · 944 Bytes
/
counting-liars.cpp
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
54
55
56
57
58
59
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = n;
vector<int> greaterThan;
vector<int> lessThan;
while(n--) {
char inequality;
int p;
cin >> inequality >> p;
if(inequality == 'L')
lessThan.push_back(p);
else if(inequality == 'G')
greaterThan.push_back(p);
}
sort(greaterThan.begin(), greaterThan.end());
sort(lessThan.begin(), lessThan.end());
int countLying = 0;
if(greaterThan.empty() || lessThan.empty()) {
cout << countLying << endl;
}
else {
int l = greaterThan.size() - 1;
int r = 0;
while(lessThan[r] < greaterThan[l]) {
if(l == 0 && r == lessThan.size() - 1) {
countLying++;
break;
} else if(l == 0){
r++;
countLying++;
} else if(r == lessThan.size() - 1) {
l--;
countLying++;
} else {
r++;
countLying++;
}
}
}
cout << countLying << endl;
return 0;
}