-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1140.cpp
54 lines (49 loc) · 1.08 KB
/
1140.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
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int N = 4e5 + 5;
struct Project {
int l, r, p;
};
inline bool operator <(const Project &a, const Project &b) {
return a.r < b.r;
}
int n, m;
ll fen[N], f[N];
vector<int> cords;
vector<Project> A;
void update(int p, ll v) {
for (; p <= m; p += p & -p) {
fen[p] = max(fen[p], v);
}
}
ll get(int p) {
ll v = 0;
for (; p >= 1; p -= p & -p) {
v = max(v, fen[p]);
}
return v;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1, l, r, p; i <= n; ++i) {
cin >> l >> r >> p;
A.push_back({l, r, p});
cords.emplace_back(l);
cords.emplace_back(r);
}
sort(all(A));
sort(all(cords));
cords.resize(unique(all(cords)) - cords.begin());
m = cords.size();
for (auto [l, r, p]: A) {
int posl = lower_bound(all(cords), l) - cords.begin() + 1;
int posr = lower_bound(all(cords), r) - cords.begin() + 1;
f[posr] = get(posl - 1) + p;
update(posr, f[posr]);
}
cout << get(m) << "\n";
return 0;
}