Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,t,l,e;
  6.     cin >> n >> t;
  7.     multimap<int, int> monster;
  8.     for (int i = 0; i < n; ++i)
  9.     {
  10.         cin >> l >> e;
  11.         monster.insert(pair<int, int>(l,e));
  12.     }
  13.     int now = 0, res = 0;
  14.     priority_queue<int, vector<int>, greater<int> > pq;
  15.     for (auto i = monster.begin(); i != monster.end();)
  16.     {
  17.         if ((i -> first)/t == now)
  18.         {
  19.             if (pq.size() < now + 1)
  20.                 pq.push(i -> second);
  21.             else if (i -> second > pq.top())
  22.             {
  23.                 pq.pop();
  24.                 pq.push(i -> second);
  25.             }
  26.             i++;
  27.         }
  28.         else
  29.         {
  30.             now = (i -> first)/t;
  31.         }
  32.     }
  33.     while (!pq.empty())
  34.     {
  35.         res += pq.top();
  36.         pq.pop();
  37.     }
  38.     cout << res << endl;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement