D_L3

Център за поддръжка

Jan 26th, 2024
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <queue>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main() {
  12.     int k, t, b, n, a;
  13.     cin >> k >> t >> b >> n;
  14.     queue<int> requests;
  15.     for(int i = 0; i < n; i ++){
  16.         cin >> a;
  17.         requests.push(a);
  18.     }
  19.     priority_queue<int, vector<int>, greater<int>> pq;
  20.    
  21.     vector<int> result;
  22.     int currTime = 0;
  23.     int groupsSorFar = 0;
  24.     while(!pq.empty() || !requests.empty()) {
  25.         if (currTime % t == 0 && !pq.empty()) {
  26.             for (int i = 0; i < k && !pq.empty(); i++) {
  27.                 result.push_back(pq.top());
  28.                 pq.pop();
  29.             }
  30.             groupsSorFar++;
  31.  
  32.             if (groupsSorFar == b)
  33.             {
  34.                 break;
  35.             }
  36.         }
  37.  
  38.         if (!requests.empty()) {
  39.             pq.push(requests.front());
  40.             requests.pop();
  41.         }
  42.         currTime++;
  43.     }
  44.    
  45.     for(int i = 0; i < result.size(); i++){
  46.         cout << result[i] << " ";
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment