Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<" smorti hyuniy : "<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef long double ld;
- const ll MAXN = 72;
- ll dp[MAXN][MAXN][MAXN]={};
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- ll n, m;
- cin >> n >> m;
- struct Point {
- ll x, type, val;
- };
- map<ll, ll> inser;
- vector<Point> line;
- for (ll i = 0; i < m; i++) {
- ll l, r, val;
- cin >> l >> r >> val;
- inser[l] = max(inser[l], val);
- inser[r] = max(inser[r], val);
- line.push_back({ l,+1,val });
- line.push_back({ r,-1,val });
- }
- auto cmp = [&](Point& a, Point& b) {
- return (a.x < b.x || (a.x == b.x && a.type > b.type));
- };
- sort(all(line), cmp);
- ll last_x = -1;
- ll ans = 0;
- multiset<ll> cur;
- ans += inser[1];
- map<ll, ll> used;
- for (Point& x : line) {
- if (last_x != -1) {
- if (used[x.x])continue;
- auto it = cur.end();
- it--;
- ans += max(inser[x.x], *it);
- ans += (x.x - last_x - 1) * (*it);
- used[x.x] = 1;
- }
- last_x = x.x;
- if (x.type == -1) {
- cur.erase(cur.find(x.val));
- }
- else {
- cur.insert(x.val);
- }
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement