Problem:


There are n processes in a queue. Each process has namei and timei.  The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue.

For example, we have the following queue with the quantum of 100ms.

A(150) - B(80) - C(200) - D(200)

First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms).

B(80) - C(200) - D(200) - A(50)

Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue.

C(200) - D(200) - A(50)

Your task is to write a program which simulates the round-robin scheduling. 

Input

n q

name1 time1

name2 time2

...

namen timen

In the first line the number of processes n and the quantum q are given separated by a single space.

In the following n lines, names and times for the n processes are given. namei and timei are separated by a single space.

Output

For each process, prints its name and the time the process finished in order.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 1000

1 ≤ timei ≤ 50000

1 ≤ length of namei ≤ 10

1 ≤ Sum of timei ≤ 1000000

Sample Input 1

5 100
p1 150
p2 80
p3 200
p4 350
p5 20

Sample Output 1

p2 180
p5 400
p1 450
p3 550
p4 800

Notes

Template in C



Sample input:
5 100
p1 150
p2 80
p3 200
p4 350
p5 20


Sample output:
p2 180
p5 400
p1 450
p3 550
p4 800

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = (i+1)%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:04:22 2018
ALDS1_3b_r リングバッファによる実装
@author: maezawa
"""

def fifo_enque(data):
    global tail
    global fifo
    fifo[tail] = data
    tail = (tail+1)%fifo_size
    
def fifo_deque():
    global head
    global fifo
    data = fifo[head]
    head = (head+1)%fifo_size
    return data

fifo_size = 100000
fifo = [0 for _ in range(fifo_size)]
head = 0
tail = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    data = [s[0], int(s[1])]
    fifo_enque(data)
    
current_time = 0
finished = []
fin_time = []

while True:
    data = fifo_deque()
    if data[1] > q:
        current_time -= q
        data[1] -= q
        fifo_enque(data)
    else:
        current_time += data[1]
        finished.append(data[0])
        fin_time.append(current_time)
    if head == tail:
        break

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))

Submission status: Wrong Answer

Solution code:
a=input().split()
n=int(a[0])
q=int(a[1])
b=[0 for i in range(2*n)]
cnt=0
for i in range(n):
    B=input().split()
    b[2*i]=B[0]
    b[2*i+1]=int(B[1])
while len(b)>0:
    tmp=b[1]-100
    if tmp>0:
        b.append(b[0])
        b.append(tmp)
        del b[0]
        del b[0]
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0],cnt)
        del b[0]
        del b[0]

Submission status: Wrong Answer

Solution code:
a=input().split()
n=int(a[0])
q=int(a[1])
b=[0 for i in range(2*n)]
cnt=0
tmp=0
for i in range(n):
    B=input().split()
    b[2*i]=B[0]
    b[2*i+1]=int(B[1])
while len(b)>0:
    tmp=b[1]-100
    if tmp>0:
        b.append(b[0])
        b.append(tmp)
        del b[0]
        del b[0]
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0],cnt)
        del b[0]
        del b[0]

Submission status: Wrong Answer

Solution code:
a=input().split()
n=(int)(a[0])
q=(int)(a[1])
b=[0 for i in range(2*n)]
cnt=0
tmp=0
for i in range(n):
    B=input().split()
    b[2*i]=B[0]
    b[2*i+1]=int(B[1])
while len(b)>0:
    tmp=b[1]-100
    if tmp>0:
        b.append(b[0])
        b.append(tmp)
        del b[0]
        del b[0]
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0],cnt)
        del b[0]
        del b[0]

Submission status: Wrong Answer

Solution code:
a=input().split()
n=(int)(a[0])
q=(int)(a[1])
b=[0 for i in range(2*n)]
cnt=0
tmp=0
for i in range(n):
    B=input().split()
    k=2*i
    b[k]=B[0]
    b[k+1]=int(B[1])
while len(b)>0:
    tmp=b[1]-100
    if tmp>0:
        b.append(b[0])
        b.append(tmp)
        del b[0]
        del b[0]
        cnt=cnt+100
    else:
        cnt=cnt+b[1]
        print(b[0],cnt)
        del b[0]
        del b[0]

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
queue = []
min_time = 10000000
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
    min_time = min(min_time, int(time))
# print(min_time)
t = 0
if q <= min_time:
    queue = [{"name": queue[i]["name"], "time":queue[i]["time"] - min_time}
             for i in range(n)]
    t = min_time * n
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue.remove(queue[0])
        print("{} {}".format(name, t))
    else:
        queue = queue[1:] + \
            [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
        t += q

Submission status: Wrong Answer

Solution code:
from collections import deque

n, q = [int(_) for _ in input().split()]
processes = deque([tuple(input().split()) for i in range(n)])

time = 0
while processes:
    process = processes.popleft()

    if int(process[1]) < q:
        time += int(process[1])
        print(process[0], time)

    else:
        time += q
        processes.append((process[0], int(process[1]) - q))

Submission status: Wrong Answer

Solution code:
n, q = [int(i) for i in input().split()]
que = []
ans_count = 0 #出力数
time = 0 #経過時間
# data読み込み
for i in range(n):
    que.append([i for i in input().split()])

while(ans_count!=n):
    pop_process = que.pop(0)
    pop_process[1] = int(pop_process[1])
    # 末尾から追加、先頭から取り出す
    if pop_process[1] < q:
        time += pop_process[1]
        print('{0} {1}'.format(pop_process[0], time))
        ans_count += 1
    else:
        time += q
        pop_process[1] -= q
        que.append(pop_process)

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if int(procs[current_proc][1]) > 100:
            procs[current_proc][1] = str(int(procs[current_proc][1]) - qms)
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += int(procs[current_proc][1])
            print("{} {}".format(procs[current_proc][0], total_time))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    total_time = 0
    current_proc = 0
    while True:
        if int(procs[current_proc][1]) > 100:
            procs[current_proc][1] = str(int(procs[current_proc][1]) - qms)
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += int(procs[current_proc][1])
            print("{} {}".format(procs[current_proc][0], total_time))
            del procs[current_proc]
            if len(procs) == 0:
                break
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if int(procs[current_proc][1]) > 100:
            procs[current_proc][1] = str(int(procs[current_proc][1]) - qms)
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += int(procs[current_proc][1])
            print("{} {}".format(procs[current_proc][0], str(total_time)))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if int(procs[current_proc][1]) > 100:
            procs[current_proc][1] = str(int(procs[current_proc][1]) - qms)
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += int(procs[current_proc][1])
            print("{}{}".format(procs[current_proc][0], str(total_time)))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
raw_procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    procs = []
    for row in raw_procs:
        name, time = row.split()
        procs.append({
            "name": name,
            "time": int(time),
        })

    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if procs[current_proc]["time"] > 100:
            procs[current_proc]["time"] = procs[current_proc]["time"] - qms
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += procs[current_proc]["time"]
            print("{} {}".format(procs[current_proc]["name"], total_time))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
process_num, qms = map(int, input().split())
raw_procs = [input() for i in range(process_num)]


if __name__ == '__main__':
    procs = []
    for row in raw_procs:
        name, time = row.split()
        procs.append({
            "name": name,
            "time": int(time),
        })

    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if procs[current_proc]["time"] > qms:
            procs[current_proc]["time"] = procs[current_proc]["time"] - qms
            total_time += qms
            if current_proc == len(procs)-1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += procs[current_proc]["time"]
            print("{} {}".format(procs[current_proc]["name"], total_time))
            del procs[current_proc]
            if current_proc >= len(procs)-1:
                current_proc = 0

Submission status: Wrong Answer

Solution code:
N, qms = map(int, input().split())

raw_proc = [input() for i in range(N)]
queue = []
for row in raw_proc:
    name, time = row.split()
    time = int(time)
    queue.append({"name": name, "time": time})

def enque(tail, p):
    tail = (tail+1) % N
    queue[tail] = p
    return tail

def deque(head):
    proc = queue[head]
    head = (head+1) % N
    return proc, head


if __name__ == '__main__':
    head = 0
    tail = N-1
    total_time = 0
    while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

class Queue:
    class Cell:
        def __init__(self,data,link=None):
            self.data=data
            self.link=link
    
    def __init__(self):
        self.size=0
        self.front=None
        self.rear=None

    def enqueue(self,x):
        if self.size==0:
            self.front = self.rear = Queue.Cell(x)
        else:
            new_cell = Queue.Cell(x)
            self.rear.link=new_cell
            self.rear=new_cell
        self.size +=1

    def dequeue(self):
        if self.size==0:
            raise IndexError
        value=self.front.data
        self.front=self.front.link
        self.size -=1
        if self.size==0:
            self.rear=None
        return value

    def isEmpty(self):
        return self.size==0

def generator(n1, n2, step=1):
    n = n1
    while n<n2:
        yield n
        n+= step

n, q = map(int, raw_input().split())
 
que = Queue()
for i in generator(0,n):
    name, time = raw_input().split()
    que.enqueue([name, int(time)])

stime = 0
while not que.isEmpty:
    job = que.dequeue()
    tmp=min(q,job[1])
    stime += tmp
    job[1] -= tmp
    if job[1]==0:
        print job[0], stime
    else:
        que.que.enqueue(job)

Submission status: Wrong Answer

Solution code:
import collections

n, q = map(int, raw_input().split())
datalist = [raw_input().split() for i in range(n)]

datalist = collections.deque(datalist)

time = 0
while len(datalist):
	data = datalist.popleft()
	data[1] = int(data[1])
	
	if data[1] <= 100:
		time += data[1]
		print data[0], time
		
	else:
		time += 100
		data[1] = data[1] - 100
		datalist.append(data)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
from Queue import Queue
import collections
start = time.clock()
i = 0
(n,q)=map(int, raw_input().split())
datalist=[raw_input().split() for _ in range(n)]
datalist=collections.deque(datalist)
#print(datalist)
while len(datalist):
    data=datalist.popleft()
    print data,datalist
    data[1]=int(data[1])
    if data[1]<=q:
        i+=data[1]
        print data[0],i
    else:
        i+=q
        data[1]-=q
        datalist.append(data)

Submission status: Time Limit Exceeded

Solution code:
nq=list(map(int,input().split()))
n=[]
p=[]
t=[]
ans1=[]
ans2=[]
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	p.append(0)
	t.append(inp[0])

cnt=0
time=0
while n!=p:
	if n[0]==0:
		x=0
		y=0
		x=n[0]
		y=t[0]
		for j in range(len(n)-1):
			n[j]=n[j+1]
			t[j]=t[j+1]
		n[len(n)-1]=x
		t[len(t)-1]=y
	
	else:	
		n[0]=n[0]-nq[1]
		if n[0]<=0:
			time=time+(int(nq[1])*(cnt+1)+int(n[0]))
			cnt=0
			n[0]=0
			x=0
			y=0
			x=n[0]
			y=t[0]
			for j in range(len(n)-1):
				n[j]=n[j+1]
				t[j]=t[j+1]
			n[len(n)-1]=x
			t[len(t)-1]=y
			ans1.append(t[len(t)-1])
			ans2.append(time)
			
			
		else:
			x=0
			y=0
			x=n[0]
			y=t[0]
			for j in range(len(n)-1):
				n[j]=n[j+1]
				t[j]=t[j+1]
			n[len(n)-1]=x
			t[len(t)-1]=y
			cnt+=1
for i in range(nq[0]):
	print(ans1[i],ans2[i])

Submission status: Time Limit Exceeded

Solution code:
nq=list(map(int,input().split()))
n=[]
p=[]
t=[]
ans1=[]
ans2=[]
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	p.append(0)
	t.append(inp[0])

cnt=0
time=0
while n!=p:
	if n[0]==0:
		x=0
		y=0
		x=n[0]
		y=t[0]
		for j in range(len(n)-1):
			n[j]=n[j+1]
			t[j]=t[j+1]
		n[len(n)-1]=x
		t[len(t)-1]=y
	
	else:	
		n[0]=n[0]-nq[1]
		if n[0]<=0:
			time=time+(int(nq[1])*(cnt+1)+int(n[0]))
			cnt=0
			n[0]=0
			x=0
			y=0
			x=n[0]
			y=t[0]
			for j in range(len(n)-1):
				n[j]=n[j+1]
				t[j]=t[j+1]
			n[len(n)-1]=x
			t[len(t)-1]=y
			ans1.append(t[len(t)-1])
			ans2.append(time)
			
			
		else:
			x=0
			y=0
			x=n[0]
			y=t[0]
			for j in range(len(n)-1):
				n[j]=n[j+1]
				t[j]=t[j+1]
			n[len(n)-1]=x
			t[len(t)-1]=y
			cnt+=1
for i in range(nq[0]):
	print(ans1[i],ans2[i])

Submission status: Time Limit Exceeded

Solution code:
n=[]
t=[]
nq=list(map(int,input().split()))
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	t.append(inp[0])
cnt1=0
while len(n)!=0:	
	n[0]=n[0]-nq[1]
	if n[0]<=0:
		cnt1=cnt1+nq[1]+n[0]
		print(t[0],cnt1)
		n.pop(0)
		t.pop(0)		
	else:
		x=0
		y=0
		x=n[0]
		y=t[0]
		for j in range(len(n)-1):
			n[j]=n[j+1]
			t[j]=t[j+1]
		n[len(n)-1]=x
		t[len(t)-1]=y
		cnt1+=nq[1]

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
A = [list(map(str,input().split())) for i in range(n)]
time = 0
flag = 1
while flag == 1:
    if int(A[0][1]) <= q: #プロセスが完了する場合
        time += int(A[0][1])
        print(A[0][1],time)
        del A[0]
    else: #プロセスが完了しない場合
        time += q
        A.append(A[0])
        del A[0]
    if len(A) == 0:
        flag = 0

Submission status: Time Limit Exceeded

Solution code:
Input = str(input())
Input = Input.split(" ")
n = int(Input[0])
q = int(Input[1])
time = 0
name = []
data = []

for i in range(n):
    Input = str(input())
    Input = Input.split(" ")
    name.append(Input[0])
    data.append(int(Input[1]))
    
while 1:
    flag = 0
    for i in range(n):
        if data[i] < 0:
            flag += 1
        elif data[i] <= q:
            time += data[i]
            data[i] = -1
            print(name[i],time)
        else:
            data[i] -= q
            time += q
        
    if flag == n:
        break

Submission status: Time Limit Exceeded

Solution code:
import copy
n,q = map(int,input().split())
s =[]

for i in range(n):
  s.append(list(input().split()))
  s[i][1]=int(s[i][1])  
keep = copy.deepcopy(s)
for l in range(n):
  keep[l][1]=0
ans = []
while(len(keep)>0):
  if s[0][1]<=q:
    ans.append(keep[0])
    for j in range(len(keep)):
        keep[j][1]+=s[0][1]
    del keep[0]
    del s[0]    
    j=0   
  else:
    s[0][1]-=q
    s.append(s.pop(0))
    keep.append(keep.pop(0))
    for j in range(len(keep)):
        keep[j][1]+=q
    j=0

for k in range(n):
  print(ans[k][0] + " " + str(ans[k][1]))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
processes = []
for i in range(n):
    name, time =  input().split()
    processes += [[name, int(time)]]

progress = 0

while len(processes):
    target = processes[0]
    if target[1] > q:
        target[1] -= q
        progress += q
        processes = processes[1:] + [target]
    else:
        progress += target[1]
        processes = processes[1:]
        print(target[0], progress)

Submission status: Time Limit Exceeded

Solution code:
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
	key,value=raw_input().split()
	dict.update({key:int(value)})
	kl.append(key)
cnt=0


while True:
	time=0
	for k in kl:
		if dict[k]<=0: time+=1
		else:
			if(dict[k]<=p):
				cnt+=dict[k]
				dict[k]=0
				print k,cnt	
			else:
				dict[k]-=p
				cnt+=p
	if time==n: break

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
    key,value=raw_input().split()
    kl.append(key)
    dict.update({key:int(value)})
   
cnt=0
time=0
count=0
while time!=n:
    for key in kl:
        if 0<dict[key]<=p:
           	cnt+=dict[key]
           	dict[key]=0
           	#del dict[key]
           	#kl.remove(key)
           	time+=1
           	print key,cnt
        elif dict[key]>p:
            dict[key]-=p
            cnt+=p

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
    key,value=raw_input().split()
    kl.append(key)
    dict.update({key:int(value)})
   
cnt=0
time=0
while time!=n:
    for key in kl[:]:
        if 0<dict[key]<=p:
           	cnt+=dict[key]
           	dict[key]=0
           	del dict[key]
           	kl.remove(key)
           	time+=1
           	print key,cnt
        elif dict[key]>p:
            dict[key]-=p
            cnt+=p

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
    key,value=raw_input().split()
    kl.append(key)
    dict.update({key:int(value)})
   
cnt=0
time=0
while time!=n:
    for key in kl[:]:
        if 0<dict[key]<=p:
           	cnt+=dict[key]
           	del dict[key]
           	kl.remove(key)
           	time+=1
           	print key,cnt
        else:
            dict[key]-=p
            cnt+=p

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
    key,value=raw_input().split()
    kl.append(key)
    dict.update({key:int(value)})
   
cnt=0
time=0
while time!=n:
    for key in kl[:]:
        if dict[key]<=p:
           	cnt+=dict[key]
           	del dict[key]
           	kl.remove(key)
           	time+=1
           	print key,cnt
        else:
            dict[key]-=p
            cnt+=p

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
dict={}
kl=[]
n,p=map(int,raw_input().split())
for i in range(n):
    key,value=raw_input().split()
    kl.append(key)
    dict.update({key:int(value)})
   
cnt=0
time=0
while time!=n:
    for key in kl[:]:
        if dict[key]<=p:
           	cnt+=dict[key]
           	#del dict[key]
           	kl.remove(key)
           	time+=1
           	print key,cnt
        else:
            dict[key]-=p
            cnt+=p

Submission status: Time Limit Exceeded

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if x_list_list[0][1] > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif x_list[0][1] <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Time Limit Exceeded

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  else:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Time Limit Exceeded

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif int(x_list_list[0][1]) <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Time Limit Exceeded

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if x_list_list[0][1] > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  else:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

Submission status: Time Limit Exceeded

Solution code:
import collections

dq = collections.deque()
N, Q = map(int, input().split())
for i in range(N):
    name, time = input().split()
    dq.append((name, int(time)))
total_time = 0
while dq:
    name, time = dq.popleft()
    total_time += min(Q, time)
    if time <= Q:
        print(name, total_time)
    else:
        dq.append((name, time))

Submission status: Time Limit Exceeded

Solution code:
nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1]), 0) for i in p]
ans = []
while len(p) != 0:
    t = p.pop(0)
    if t[1] > q:
        p = [(s[0], s[1], s[2]+q) for s in p]
        p.append((t[0], t[1]-q, t[2]+q))
    elif t[1] <= q:
        p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[2] + t[1]))
for t in ans:
    print('{0} {1}'.format(t[0], t[1]))

Submission status: Time Limit Exceeded

Solution code:
# input
n, q = map(int, raw_input().split())
procs = [raw_input().split() for i in xrange(n)]

# procsessing
cnt, lack = 0, 1
while lack > 0:
    lack = 0
    for i in xrange(n):
        t = int(procs[i][1])
        if t == 0:
            continue
        if t <= q:
            cnt += t
            t = 0
            print procs[i][0], cnt
        else: # t >= q
            cnt += q
            t = t - q
            lack += t
        procs[i][1] = str(t)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n, q = list(map(int, input().split(' ')))

    process = []
    for i in range(n):    
        process.append(input().split(' '))
        process[i][1] = int(process[i][1])
    
    timer = 0
    fin_time = []
    num_of_proc = n    
    while num_of_proc > 0:
        for i in range(n):
            if process[i][1] == 0:
              continue  
            elif process[i][1] <= q:
                num_of_proc -= 1
                timer += process[i][1]
                process[i][1] = 0
                fin_time.append([process[i][0], timer])
            else:
                timer += q
                process[i][1] -= q
    
    for t in fin_time:
        print(t[0], t[1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


n, q = list(map(int, input().split(' ')))

process = []
for i in range(n):    
    process.append(input().split(' '))
    process[i][1] = int(process[i][1])

timer = 0
fin_time = []
num_of_proc = n    
while num_of_proc > 0:
    for i in range(n):
        if process[i][1] == 0:
          continue  
        elif process[i][1] > q:
            timer += q
            process[i][1] -= q
        else:
            num_of_proc -= 1
            timer += process[i][1]
            process[i][1] = 0
            fin_time.append([process[i][0], timer])

for t in fin_time:
    print(t[0], t[1])

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
#?????\???
#??????????????¨????§?????????¨?????¨?????????????????????????????????????????????????????????
def rrs(quantum, process):
    finished_process = []

    time_queue = Queue()
    name_queue = Queue()
    
    current_time = 0

    for name, time in process:
        time = int(time)
        time_queue.enqueue(time)
        name_queue.enqueue(name)

    while time_queue.data:
        time = time_queue.dequeue()
        name = name_queue.dequeue()
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            time_queue.enqueue(time - quantum)
            name_queue.enqueue(name)
            
    return finished_process


class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
    
def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
    
if __name__ == "__main__":
    main()