Advertisement
FellaFiesto

C

May 31st, 2025
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5.  
  6. #define en '\n'
  7. #define bg(x) begin(x)
  8. #define all(x) bg(x), end(x)
  9. #define fin(x) for (auto &it : x) cin >> it
  10. #define fout(x) for (auto &it : x) cout << it << ' '; cout << en
  11.  
  12. using namespace std;
  13.  
  14. using ll = long long;
  15. using i32 = int32_t;
  16.  
  17. template<typename T>
  18. using V = vector<T>;
  19. using vi = V<int>;
  20. using vvi = V<vi>;
  21.  
  22. void solve() {
  23.     int n; cin >> n;
  24.     vvi v(n, vi(3));
  25.     for (size_t i = 0; i < n; i++)
  26.     {
  27.         fin(v[i]);
  28.     }
  29.     sort(all(v), [](vi a, vi b) {
  30.         return a[2] > b[2];
  31.     });
  32.     ll ans = 0;
  33.     map<int, int> cords;
  34.     for (size_t i = 0; i < n; i++)
  35.     {
  36.         int left = v[i][0];
  37.         int right = v[i][1];
  38.         if (cords.size() == 0) {
  39.  
  40.             cords[left] = right;
  41.             continue;
  42.         }
  43.  
  44.         auto it = cords.upper_bound(left);
  45.         bool canAdd = true;
  46.         if (it != cords.end()) {
  47.             if (right > (*it).first) {
  48.                 canAdd = false;
  49.             }
  50.         }
  51.         if (it != cords.begin()) {
  52.             it--;
  53.             if (left < (*it).second) {
  54.                 canAdd = false;
  55.             }
  56.         }
  57.         if (!canAdd) ans += v[i][2];
  58.         else {
  59.             cords[left] = right;
  60.         }
  61.         // fout(v[i]);
  62.     }
  63.     cout << ans;
  64. }
  65.  
  66. i32 main()
  67. {
  68.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  69.  
  70.     solve();
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement