这题就是一个小顶堆而已
注意结构体里小于号的重载 重载结果的不同会导致写法的不同
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#define eps 1e-5
#define MAXN 111111
#define MAXM 111111
#define INF 1000000000
using namespace std;
struct wwj
{int id, inter, tm;wwj(){}wwj(int a, int b){id = a; inter = b;}bool operator >(const wwj& a)const{if(a.tm == tm) return a.id < id;else return a.tm < tm;}
}p[100005], q[11111];
char s[20];
int r;
void up(int i)
{int j;while(i > 1){j = i / 2;if(q[j] > q[i]) swap(q[i], q[j]);else break;i = j;}
}
void down(int i)
{int j;while(i * 2 <= r){j = i * 2;if(j + 1 <= r && q[j] > q[j + 1]) j++;if(q[i] > q[j]) swap(q[i], q[j]);else break;i = j;}
}
void del()
{swap(q[1], q[r]);r--;down(1);
}
void insert(wwj x)
{q[++r] = x;up(r);
}
int main()
{int cnt = 0, k;r = 0;while(scanf("%s", s) != EOF){if(s[0] == '#') break;scanf("%d%d", &p[cnt].id, &p[cnt].inter);p[cnt].tm = p[cnt].inter;insert(p[cnt]);cnt++;}scanf("%d", &k);while(k--){wwj A = q[1];del();printf("%d\n", A.id);A.tm += A.inter;insert(A);}return 0;
}