-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1203.cpp
42 lines (35 loc) · 784 Bytes
/
1203.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <queue>
#include <string>
struct Query {
int id, step, next;
};
bool operator<(const Query &x, const Query &y)
{
return x.next == y.next ? x.id > y.id : x.next > y.next;
}
bool operator>(const Query &x, const Query &y)
{
return x.next == y.next ? x.id < y.id : x.next < y.next;
}
int main(void)
{
int count, x, y;
std::string buffer;
std::priority_queue<Query> q;
while (1) {
std::cin >> buffer;
if (buffer[0] == '#') break;
std::cin >> x >> y;
q.push(Query{x, y, y});
}
std::cin >> count;
while (count--) {
auto top = q.top();
q.pop();
std::cout << top.id << std::endl;
top.next += top.step;
q.push(top);
}
return 0;
}