File Edit Options Buffers Tools C Help
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100005
typedef struct pp{
  char name[15];
  int t;
}P;
P Q[LEN+1];
int head=0, tail, n;
void enqueue(P x){
  strcpy( Q[tail].name,x.name);
  Q[tail].t=x.t;
  tail++;
}
int main(){
  int elaps = 0, c;
  int i, q,l=0;
  scanf("%d %d", &n, &q);
  if(n>=10000) exit(1);
  tail=n+1;
  for ( i = 1; i <= n; i++){
    scanf("%s%d", Q[i].name,&Q[i].t);
  }
  i=1;
  while(1){
    if(Q[i].t>q){
      Q[i].t-=q;
      enqueue(Q[i]);
      elaps+=q;
       }

    else if(Q[i].t<=q){
      elaps+=Q[i].t;
      printf("%s %d\n",Q[i].name,elaps);
      l++;
      if(l==n)break;;
    }
    i++;

  }

  return 0;
}