Please enter your email address or userHandle.
#include<bits/stdc++.h> using namespace std; bool comp(const pair<pair<long long int, long long int>, long long int> &a, const pair<pair<long long int, long long int>, long long int> &b){ if(a.first.second < b.first.second) return true; return false; } int findit(vector<pair<pair<long long int, long long int>, long long int>> &v, int i){ int low = 0, high = i-1; while(low <= high){ int mid = low + (high-low)/2; if(v[mid].first.second < v[i].first.first){ if(v[mid+1].first.second < v[i].first.first) low = mid+1; else return mid; } else high = mid-1; } return -1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<pair<long long int, long long int>, long long int>> v(n); for(int i=0;i<n;++i) cin >> v[i].first.first >> v[i].first.second >> v[i].second; sort(v.begin(), v.end(), comp); long long int ans[n]; ans[0] = v[0].second; for(int i=1;i<n;++i){ long long int tmp = v[i].second; int search = findit(v, i); if(search != -1) tmp += ans[search]; ans[i] = max(ans[i-1], tmp); } cout << ans[n-1] << endl; return 0; }
https://ide.geeksforgeeks.org/hCuD7Po9XT
7