Advertisement
ivnikkk

Untitled

Mar 30th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(l) cerr<<" smorti hyuniy : "<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(a) a.begin(), a.end()
  6. typedef long long ll;
  7. typedef long double ld;
  8. const ll MAXN = 72;
  9. ll dp[MAXN][MAXN][MAXN]={};
  10. signed main() {
  11. #ifdef _DEBUG
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14. #endif
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(nullptr);
  17.     ll n, m;
  18.     cin >> n >> m;
  19.     struct Point {
  20.         ll x, type, val;
  21.     };
  22.     map<ll, ll> inser;
  23.     vector<Point> line;
  24.     for (ll i = 0; i < m; i++) {
  25.         ll l, r, val;
  26.         cin >> l >> r >> val;
  27.         inser[l] = max(inser[l], val);
  28.         inser[r] = max(inser[r], val);
  29.         line.push_back({ l,+1,val });
  30.         line.push_back({ r,-1,val });
  31.     }
  32.     auto cmp = [&](Point& a, Point& b) {
  33.         return (a.x < b.x || (a.x == b.x && a.type > b.type));
  34.     };
  35.     sort(all(line), cmp);
  36.     ll last_x = -1;
  37.     ll ans = 0;
  38.     multiset<ll> cur;
  39.     ans += inser[1];
  40.     map<ll, ll> used;
  41.     for (Point& x : line) {
  42.         if (last_x != -1) {
  43.             if (used[x.x])continue;
  44.             auto it = cur.end();
  45.             it--;
  46.             ans += max(inser[x.x], *it);
  47.             ans += (x.x - last_x - 1) * (*it);
  48.             used[x.x] = 1;
  49.         }
  50.         last_x = x.x;
  51.         if (x.type == -1) {
  52.             cur.erase(cur.find(x.val));
  53.         }
  54.         else {
  55.             cur.insert(x.val);
  56.         }
  57.     }
  58.     cout << ans << '\n';
  59. }
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement