Advertisement
Derga

Untitled

Aug 22nd, 2023
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.     queue<pair<int, int>> q;
  10.     int current_time = 0;
  11.     vector<int> ans(n);
  12.  
  13.     auto update_answer = [&]() {
  14.         current_time = max(q.front().first + 20, current_time + 20);
  15.         ans[q.front().second] = current_time;
  16.     };
  17.  
  18.     for (int i = 0; i < n; ++i) {
  19.         int h, m, p;
  20.         cin >> h >> m >> p;
  21.         int time = h * 60 + m;
  22.         while (q.size() > 0 && current_time <= time) {
  23.             q.pop();
  24.             if (q.size() > 0) {
  25.                 update_answer();
  26.             }
  27.         }
  28.         if (q.size() <= p) {
  29.             q.emplace(time, i);
  30.             if (q.size() == 1) {
  31.                 update_answer();
  32.             }
  33.         } else {
  34.             ans[i] = time;
  35.         }
  36.     }
  37.     while (q.size() > 0) {
  38.         q.pop();
  39.         if (q.size() > 0) {
  40.             update_answer();
  41.         }
  42.     }
  43.  
  44.     for (int i = 0; i < n; ++i) {
  45.         cout << ans[i] / 60 << " " << ans[i] % 60 << "\n";
  46.     }
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement