Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main() {
- int k, t, b, n, a;
- cin >> k >> t >> b >> n;
- queue<int> requests;
- for(int i = 0; i < n; i ++){
- cin >> a;
- requests.push(a);
- }
- priority_queue<int, vector<int>, greater<int>> pq;
- vector<int> result;
- int currTime = 0;
- int groupsSorFar = 0;
- while(!pq.empty() || !requests.empty()) {
- if (currTime % t == 0 && !pq.empty()) {
- for (int i = 0; i < k && !pq.empty(); i++) {
- result.push_back(pq.top());
- pq.pop();
- }
- groupsSorFar++;
- if (groupsSorFar == b)
- {
- break;
- }
- }
- if (!requests.empty()) {
- pq.push(requests.front());
- requests.pop();
- }
- currTime++;
- }
- for(int i = 0; i < result.size(); i++){
- cout << result[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment