-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathed170.cpp
More file actions
41 lines (32 loc) · 949 Bytes
/
Copy pathed170.cpp
File metadata and controls
41 lines (32 loc) · 949 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool compare(int value, pair<int,pair<int,int>>& p){
return value < p.first;
}
ll findMaxWork(vector<pair<int,pair<int,int>>>&nums, int curr, vector<ll>&dp){
if(curr==nums.size()){
return 0;
}
if(dp[curr]!=-1){
return dp[curr];
}
int endTime = nums[curr].second.first;
int findIndex = upper_bound(nums.begin(),nums.end(),endTime,compare)-nums.begin();
ll pick = nums[curr].second.second + findMaxWork(nums,findIndex,dp);
ll notPick = findMaxWork(nums,curr+1,dp);
return dp[curr] = max(pick,notPick);
}
int main(){
int x;
cin>>x;
vector<pair<int,pair<int,int>>> nums;
for(int i=0;i<x;i++){
int start,end,cost;
cin>>start>>end>>cost;
nums.push_back({start,{end,cost}});
}
sort(nums.begin(),nums.end());
vector<ll>dp(nums.size(),-1);
cout<<findMaxWork(nums,0,dp);
}