// 題意: 給出一些查詢口令,每個命令有一個編號和一個周期,輸出前k個執行的命令的編號.
// sample里要求輸出前5個執行的命令的編號,那么前5個執行的時間分別為
// 時間點:200(編號:2004), 300(2005), 400(2004), 600(2004), 600(2005)
// 兩個命令都能達到600這個時間點,但根據題意先輸出編號小的,即先輸出2004
#include<iostream> //優先隊列
#include<string>
#include<queue>
using namespace std;
struct Node
{
int p,id; //id 代表 ID-number, p 代表 Period
int t; //t 代表 請求到達的時間點
bool operator<(const Node& other) const
{
if(t==other.t)
return id>other.id; //時間點相等時編號小的先出隊
else
return t>other.t; //時間點小的先出隊
}
}node;
priority_queue<Node> q;
int main()
{
char s[10];
while(scanf("%s",s)&&strcmp(s,"#")!=0)
{
scanf("%d%d",&node.id,&node.p);
node.t=node.p;
q.push(node);
}
int k;
scanf("%d",&k);
while(k--) //輸出前k個執行的命令的編號
{
node = q.top();
q.pop();
printf("%d\n",node.id);
node.t+=node.p;
q.push(node);
}
return 0;
}