Guest User

Untitled

a guest
Aug 3rd, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <algorithm>
  2. #include <deque>
  3. #include <iostream>
  4. #include <queue>
  5. #include <vector>
  6.  
  7. struct proc {
  8.  
  9.     proc(int wf, int i)
  10.         : when_free(wf)
  11.         , id_(i)
  12.     {
  13.     }
  14.     void update_time(int tm)
  15.     {
  16.         when_free = tm;
  17.     }
  18.     int time() const { return when_free; }
  19.     int id() const { return id_; }
  20.     friend bool cmp(const proc& lhs, const proc& rhs);
  21.  
  22. private:
  23.     int when_free;
  24.     int id_;
  25. };
  26.  
  27. bool cmp(const proc& lhs, const proc& rhs)
  28. {
  29.     if (lhs.when_free == rhs.when_free)
  30.         return lhs.id() < rhs.id();
  31.     return lhs.when_free < rhs.when_free;
  32. }
  33.  
  34. int main()
  35. {
  36.     std::priority_queue<proc, std::vector<proc>, decltype(cmp)> pq(cmp);
  37.     pq.push(proc(0, 0));
  38.     pq.push(proc(1, 0));
  39.     /*int n; // proc
  40.     int m; // tasks
  41.     std::cin >> n >> m;
  42.     std::vector<int> tasks(m);
  43.     for (auto & e : tasks) std::cin >> e;
  44.     */
  45.     std::cout << pq.top().time();
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment