-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_01203.cpp
63 lines (56 loc) · 1.45 KB
/
prob_01203.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define rep(i,a,b) for(i=a;i<b;++i)
#define vectIter(vect) for(auto &val: vect)
#define mapIter(map_) for(auto &val_: map_)
#define gc getchar_unlocked
#define si(n) scanf("%d",&n)
#define sii(m,n) scanf("%d%d",&m,&n)
#define ssi(str,a) scanf("%s%d",str,&a)
#define sis(a,str) scanf("%d%s",&a,str)
#define ss(str) scanf("%s",str)
using namespace std;
#define INF 999999999
typedef struct Query{
int q_num;
int period;
int next_occur;
Query(int q_num_, int period_, int next_occur_=INF):
q_num(q_num_), period(period_),
next_occur(next_occur_){};
void set_next_occur(int num){
next_occur= num;
}
bool operator<(const struct Query& q1)const{
if(next_occur > q1.next_occur) return true;
else if(next_occur == q1.next_occur && q_num > q1.q_num)
return true;
return false;
}
}query;
struct functor{
bool operator()(const query& q1, const query& q2)const{
if(q1.next_occur> q2.next_occur)
return true;
else if(q1.next_occur== q2.next_occur && q1.q_num > q2.q_num)
return true;
return false;
}
};
int main(){
int q_num, period,k;
char str[10];
// priority_queue<query, vector<query>, functor > pq; // could also have been used
priority_queue<query,vector<query> > pq;
while(ss(str),str[0]!='#'){
sii(q_num,period);
pq.push(query(q_num,period,period));
}
si(k);
while(k--){
query q= pq.top();
pq.pop();
printf("%d\n",q.q_num);
q.set_next_occur(q.period+q.next_occur);
pq.push(q);
}
}