Guest User

Horizon

a guest
Jun 9th, 2015
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. typedef unsigned long long ll;
  4. using namespace std;
  5.  
  6. #define all(x) x.begin(), x.end()
  7. #define f(i,a,b) for(int i = (a); i <= (b); i++)
  8. #define fd(i,a,b) for(int i = (a); i >= (b); i--)
  9. #define mp make_pair
  10. #define faster_io() ios_base::sync_with_stdio(false)
  11. #define pb push_back
  12. #define pii pair<int,int>
  13. #define SZ(x) ((int)x.size())
  14. #define vii vector<pair<int,int>>
  15.  
  16. const int INF = 1000000007;
  17. const ll INFLL = 100000000000000000ll;
  18. const ll MOD = 1000000007;
  19.  
  20. // ----------------------------------------------------------------------------------------------------------
  21.  
  22. int N;
  23. multiset<int,greater<int>> S;
  24. multiset<pair<pii,int>> Events;
  25.  
  26. int main()
  27. {
  28.     cin >> N;
  29.     f(i,1,N)
  30.     {
  31.         int l,r,h;
  32.         scanf("%d %d %d", &l, &r, &h);
  33.         Events.insert({{l,0},h});
  34.         Events.insert({{r,1},h});
  35.     }
  36.  
  37.     int last = 0;
  38.     ll ans = 0;
  39.  
  40.     for(pair<pii,int> p : Events)
  41.     {
  42.         int x = p.first.first, t = p.first.second, h = p.second;
  43.         if(!S.empty())
  44.         {
  45.             ll h = *S.begin();
  46.             ans += h * (x-last);
  47.         }
  48.  
  49.         if(t==0) S.insert(h);
  50.         else
  51.         {
  52.             auto it = S.find(h);
  53.             S.erase(it);
  54.         }
  55.  
  56.         last = x;
  57.     }
  58.  
  59.     cout << ans;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment