-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1276.cpp
57 lines (46 loc) · 1.07 KB
/
1276.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
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef struct {
int y;
int x1;
int x2;
}Pos;
vector<Pos> vec;
int n, answer;
bool comp(Pos& p1, Pos& p2) {
return p1.y > p2.y;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; ++i) {
Pos temp;
int y, x1, x2;
cin >> y >> x1 >> x2;
temp.y = y;
temp.x1 = x1;
temp.x2 = x2;
vec.push_back(temp);
}
sort(vec.begin(), vec.end(), comp);
for (int i = 0; i < n; ++i) {
answer += 2 * vec[i].y;
int x1 = vec[i].x1, x2 = vec[i].x2 - 1;
for (int j = i + 1; j < n; ++j) {
if (x1 >= vec[j].x1 && x1 < vec[j].x2) {
answer -= vec[j].y;
break;
}
}
for (int j = i + 1; j < n; ++j) {
if (x2 >= vec[j].x1 && x2 < vec[j].x2) {
answer -= vec[j].y;
break;
}
}
}
cout << answer;
return 0;
}