-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path3027.cpp
51 lines (41 loc) · 803 Bytes
/
3027.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
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
struct line {
int x;
int y;
int w;
};
bool compare(line a, line b) {
return a.y < b.y;
}
int main() {
int n;
cin >> n;
line *l = new line[n];
int *dp = new int[n];
for(int i=0; i<n; i++) {
cin >> l[i].x >> l[i].y >> l[i].w;
dp[i]=0;
}
sort(l,l+n,compare);
dp[0] = l[0].w;
for(int i=1; i<n; i++) {
int max_j=0;
for(int j=0; j<i; j++) {
if(l[j].y<=l[i].x) {
max_j = max(max_j, dp[j]);
}
}
dp[i] = max_j + l[i].w;
//cout << dp[i-1] << endl;
}
cout << dp[n-1];
return 0;
}