Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <fstream>
  2. #include <queue>
  3. using namespace std;
  4. priority_queue <long long > pq;
  5. priority_queue <long long > q2;
  6. int main()
  7. {
  8. ifstream cin("magazin.in");
  9. ofstream cout("magazin.out");
  10. int n,k,cz,x,cnt=0,s,a,nr;
  11. cin >> n >> k;
  12. for(int i=0;i<n;i++)
  13. {
  14. cin >> cz >> a;
  15. if(cz==1)
  16. pq.push(a);
  17. else
  18. {
  19. cnt=0;
  20. s=pq.size();
  21. while(cnt<s-a)
  22. {
  23. x=pq.top();
  24. q2.push(x);
  25. pq.pop();
  26. cnt++;
  27. }
  28. nr=pq.top();
  29. pq.pop();
  30. cout << nr << endl;
  31. while(q2.empty()==false)
  32. {
  33. x=q2.top();
  34. pq.push(x);
  35. q2.pop();
  36. }
  37. }
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement