Repository navigation
Expand file tree
/
Copy pathDemons.cpp
More file actions
68 lines (59 loc) · 1.63 KB
/
Copy pathDemons.cpp
File metadata and controls
68 lines (59 loc) · 1.63 KB
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
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Demon {
int attack;
int security;
public:
Demon(int attack = 0, int security = 0) {
this->attack = attack;
this->security = security;
}
int getAttack() const {
return this->attack;
}
int getSecurity() const {
return this->security;
}
bool operator<(const Demon& other) {
return attack < other.attack&& security < other.security;
}
};
bool sortByAttack(const Demon& a, const Demon& b) {
return a.getAttack() < b.getAttack();
}
bool sortBySecurity(const Demon& a, const Demon& b) {
return a.getSecurity() < b.getSecurity();
}
int findCount(vector<Demon>& demons) {
vector<Demon> result;
for (unsigned int i = 0; i < demons.size(); i++) {
auto itterator = lower_bound(result.begin(), result.end(), demons[i]);
if (itterator == result.end()) {
result.push_back(demons[i]);
}
else {
*itterator = demons[i];
}
}
return result.size();
}
int main() {
int n;
cin >> n;
int attack, security;
vector<Demon> demons;
for (int i = 0; i < n; i++) {
cin >> security;
cin >> attack;
demons.push_back(Demon(security, attack));
}
stable_sort(demons.begin(), demons.end(),sortByAttack);
int count_1 = findCount(demons);
stable_sort(demons.begin(), demons.end(), sortBySecurity);
int count_2 = findCount(demons);
int count = max(count_1, count_2);
cout << count << endl;
return 0;
}