hkshakib

Untitled

Mar 17th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> > pq;
  6. vector<pair<int,int>>pq1;
  7. map<int,int>mp;
  8. string s;
  9. int num,time;
  10. while(cin>>s && s[0]!='#')
  11. {
  12. cin>>num>>time;
  13. pq.push({time,num});
  14. mp[num]=time;
  15. }
  16. int k;
  17. cin>>k;
  18. int kk=k;
  19. while(k--)
  20. {
  21. pq1.push_back({pq.top().first,pq.top().second});
  22. int y = pq.top().second;
  23. pair<int, int> Top;
  24. Top.first = pq.top().first + mp[y];
  25. Top.second = pq.top().second;
  26. pq.pop();
  27. pq.push(Top);
  28. }
  29. for(int i=0; i<kk; i++)
  30. {
  31. cout<<pq1[i].second<<endl;
  32. }
  33. }
Add Comment
Please, Sign In to add comment