#include <iostream>                                                                                   
#include <vector>                                                                                     #include <sstream>                                                                                    
#include <map>                                                                                        
#include <queue>                                                                                      
                                                                                                      
using namespace std;                                                                                  
                                                                                                      
int main()                                                                                            
{                                                                                                     
  int n,q;                                                                                            
  //  string s;                                                                                       
  //  pair<string,int> task;                                                                          
  queue<pair<string,int> > qu;                                                                        
  for(;cin>>n>>q;)                                                                                    
    {                                                                                                       for(int i=0;i<n;i++)                                                                            
        {                                                                                             
          string s;                                                                                   
          int tmp;                                                                                              cin>>s>>tmp;                                                                                
          qu.push(pair<string,int>(s,tmp));                                                           
        }                                                                                             
      int time=0;                                                                                           while(!qu.empty())                                                                              
        {                                                                                             
         string s= qu.front().first;                                                                  
         int tmp= qu.front().second;                                                                  
         qu.pop();                                                                                    
         if(tmp>q)                                                                                    
           {                                                                                          
             time+=q;                                                                                 
             tmp-=q;                                                                                  
             qu.push(pair<string,int>(s,tmp));                                                        
           }                                                                                          
         else                               
          {                                                                                          
             time+=tmp;                                                                               
             cout<<s<<" "<<time<<endl;                                                                           }                                                                                          
        }                                                                                             
    }                                                                                                 
                                                                                                      }                                                                                                     
                                                                                                      
                                                                                                      
               

Measured memory_bytes: 4404