-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProjects.cpp
48 lines (41 loc) · 973 Bytes
/
Projects.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
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
struct Project{
int s,e,r;
};
bool comp(Project A,Project B){
if(A.e!=B.e) return A.e<B.e;
return A.s<B.s;
}
int main(){
int n;
cin>>n;
Project pro[n];
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
pro[i] = {a,b,c};
}
sort(pro,pro+n,comp);
int st[n],en[n];
for(int i=0;i<n;i++){
st[i] = pro[i].s;
en[i] = pro[i].e;
}
ll mx = 0;
ll profit[n] = {0};
ll maxProfit[n] = {0};
for(int i=0;i<n;i++){
auto pos = lower_bound(en,en+n,st[i])-en;
// cout<<pro[i].s<<" "<<pro[i].e<<" "<<pos<<endl;
if( pos == 0 ) profit[i] = pro[i].r;
else profit[i] = pro[i].r+maxProfit[pos-1];
if(i) maxProfit[i] = max(maxProfit[i-1],profit[i]);
else maxProfit[0] = profit[0];
}
cout<<maxProfit[n-1]<<endl;
}