大意略。
优先队列模拟。
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1010;
char str[maxn];
int n;
struct Argus
{
int time, num, period;
bool operator < (const Argus &a) const
{
if(a.time != time) return a.time < time;
return a.num < num;
}
};
priority_queue<Argus> Q;
void init()
{
while(!Q.empty()) Q.pop();
}
void read_case()
{
init();
Argus a;
int num, period;
while(str[0] != '#')
{
scanf("%d%d", &num, &period);
a.time = period, a.num = num, a.period = period; Q.push(a);
scanf("%s", str);
}
scanf("%d", &n);
}
void solve()
{
Argus b;
read_case();
int ans = 0;
for(int i = 0; i < n; i++)
{
b = Q.top(); Q.pop();
printf("%d\n", b.num);
b.time += b.period;
Q.push(b);
}
}
int main()
{
while(~scanf("%s", str))
{
solve();
}
return 0;
}