原题链接:https://vjudge.net/contest/418512#problem/B
#include <stdio.h>
#include <string.h>
#define len 1000005
typedef struct pp
{
char name[100];
int t;
} P;
P Q[len];
int a, b, head, tail;
P dequeue()
{
P x = Q[head];
head = (head + 1) % len;
return x;
}
void enqueue(P x)
{
Q[tail] = x;
tail = (tail + 1) % len;
}
int min(int n1, int n2)
{
return n1 > n2 ? n2 : n1;
}
int main()
{
int sum = 0;
P u;
scanf("%d %d", &a, &b);
head = 1; tail = a + 1;
for(int i = 1; i <= a; i++)
{
scanf("%s", Q[i].name);
scanf("%d", &Q[i].t);
}
while (head != tail)
{
u = dequeue();
if(u.t <= b)
{
sum += u.t;
printf("%s %d\n", u.name, sum);
}
else
{
sum += b;
u.t -= b;
enqueue(u);
}
}
/*
int c;
while(head != tail)
{
u = dequeue();
c = min(b, u.t);
u.t -= c;
sum += c;
if(u.t > 0) enqueue(u);
else
printf("%s %d\n", u.name, sum);
}
*/
return 0;
}