Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef unsigned long long ll;
- using namespace std;
- #define all(x) x.begin(), x.end()
- #define f(i,a,b) for(int i = (a); i <= (b); i++)
- #define fd(i,a,b) for(int i = (a); i >= (b); i--)
- #define mp make_pair
- #define faster_io() ios_base::sync_with_stdio(false)
- #define pb push_back
- #define pii pair<int,int>
- #define SZ(x) ((int)x.size())
- #define vii vector<pair<int,int>>
- const int INF = 1000000007;
- const ll INFLL = 100000000000000000ll;
- const ll MOD = 1000000007;
- // ----------------------------------------------------------------------------------------------------------
- int N;
- multiset<int,greater<int>> S;
- multiset<pair<pii,int>> Events;
- int main()
- {
- cin >> N;
- f(i,1,N)
- {
- int l,r,h;
- scanf("%d %d %d", &l, &r, &h);
- Events.insert({{l,0},h});
- Events.insert({{r,1},h});
- }
- int last = 0;
- ll ans = 0;
- for(pair<pii,int> p : Events)
- {
- int x = p.first.first, t = p.first.second, h = p.second;
- if(!S.empty())
- {
- ll h = *S.begin();
- ans += h * (x-last);
- }
- if(t==0) S.insert(h);
- else
- {
- auto it = S.find(h);
- S.erase(it);
- }
- last = x;
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment