cses projects solution

Solutions on MaxInterview for cses projects solution by the best coders in the world

showing results for - "cses projects solution"
Julie
21 Feb 2018
1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5  int n;
6  cin >> n;
7  map<int,int> compress;
8  vector<int> a(n),b(n),p(n);
9  for (int i = 0; i < n; i++) {
10    cin >> a[i] >> b[i] >> p[i];
11    b[i]++;
12    compress[a[i]], compress[b[i]];
13  }
14
15  int coords = 0;
16  for (auto&v : compress) {
17    v.second = coords++;
18  }
19
20  vector<vector<pair<int,int>>> project(coords);
21  for (int i = 0; i < n; i++) {
22    project[ compress[b[i]] ].emplace_back( compress[a[i]], p[i] );
23  }
24
25  vector<long long> dp(coords, 0);
26  for (int i = 0; i < coords; i++) {
27    if (i > 0) {
28      dp[i] = dp[i-1];
29    }
30    for (auto p : project[i]) {
31      dp[i] = max(dp[i], dp[p.first]+p.second);
32    }
33  }
34  cout << dp[coords-1] << endl;
35}
similar questions
queries leading to this page
cses projects solution