Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <sstream>
- #include <iterator>
- using namespace std;
- using Ttime = long long int;
- using T = std::pair<Ttime, int>;
- template<class InputIt>
- void pq(InputIt is, ostream &os) {
- std::priority_queue <T, vector <T>, greater<T>> q;
- int n, m;
- n = *is++;
- m = *is;
- T value{0, 0};
- Ttime t;
- for (auto i = 0; i < m; ++i) {
- t = *++is;
- os << value.second << " " << value.first << "\n";
- if (t > 0) {
- q.push({t + value.first, value.second});
- if (q.size() >= n) {
- value = q.top();
- q.pop();
- }
- else
- value.second++;
- }
- }
- }
- int main() {
- std::vector<int> v1 = {16, 12, 4, 5, 2, 0, 1, 0, 7, 2, 6, 8, 0, 0};
- std::vector<int> v2 = {1, 12, 2, 0, 4, 3, 9, 8, 4, 9, 0, 4, 3, 2};
- //pq(v1.begin(), cout);
- //pq(v2.begin(), cout);
- pq(istream_iterator<int> (cin), cout);
- }
Add Comment
Please, Sign In to add comment