#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxx = 100000 + 10;
struct task {
char name[100];
int t;
};
queue<task> Queue;
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 0; i < n; i++) {
task t;
scanf("%s %d", t.name, &t.t);
Queue.push(t);
}
int nowtime = 0;
while (!Queue.empty()) {
task u = Queue.front();
Queue.pop();
int c = min(q, u.t);
u.t -= c;
nowtime += c;
if (u.t > 0) {
Queue.push(u);
}
else {
printf("%s %d\n", u.name, nowtime);
}
}
return 0;
}
ALDS1_3_B 2018-2-21
最新推荐文章于 2020-08-07 09:45:21 发布