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:
import sys
n, q = map(int, input().split())
queue = [[label, int(num)] for label, num in map(lambda line: line.strip().split(), sys.stdin.readlines())] 
i = 0
while len(queue) > 0:
    queue[i%len(queue)][1] -= q
    if queue[i%len(queue)][1] <= 0:
        print("{} {}".format(queue[i%len(queue)][0], i*q + q + queue[i%len(queue)][1]))
        queue.pop(i%len(queue))
    i += 1

Submission status: Wrong Answer

Solution code:
import sys
n, q = map(int, input().split())
queue = [[label, int(num)] for label, num in map(lambda line: line.strip().split(), sys.stdin.readlines())] 
i = 0
time = 0
while len(queue) > 0:
    time += q
    queue[i%len(queue)][1] -= q
    if queue[i%len(queue)][1] <= 0:
        time += queue[i%len(queue)][1]
        print("{} {}".format(queue[i%len(queue)][0], time))
        queue.pop(i%len(queue))
        i -= 1
    i += 1

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())

tmp =  [input().split() for i in range(n)]
a = [[name,int(time)] for name,time in tmp]

total_time = 0

count = 0
while(a):
    current = a.pop()
    if(current[1] > q):
        current[1] -= q
        a.append(current)
        total_time += q
    else:
        total_time += current[1]
        print(current[0],total_time,sep = " ")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]))
    
for loop in range(100):
    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: Wrong Answer

Solution code:
pnum,mtime = map(int,input().split(" "))

total = [list(input().split(" ")) for _ in range(pnum)]

print(total)

cnt=0
tcnt=0
while len(total) > 0:
	ztime = int(total[0][1]) - mtime
	if ztime <= 0:
		tcnt += int(total[0][1])
		print(total[0][0],int(tcnt))
		total.pop(0)
	else:
		total.append([total[0][0],ztime])
		total.pop(0)
		tcnt += mtime
	cnt += 1

Submission status: Wrong Answer

Solution code:
from collections import deque

if __name__ == "__main__":
    n, q = input().split()
    n, q = int(n), int(q)
    s = 0
    a = deque([list(map(str,input().split())) for _ in range(n)])

    while len(a):
        x = a.popleft()
        if int(x[1]) < q:
            s += int(x[1])
            print(x[0],s)
        else:
            x[1] = str(int(x[1]) - q)
            s += q
            a.append(x)

Submission status: Wrong Answer

Solution code:
# Queue

class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1
            return self.queue.pop()
        else:
            print("there aren't enough values in Queue")

def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():
        elapsed += q
        job = queue.dequeue()
        job['time'] = job['time'] - q
        if job['time']>0:
            queue.enqueue(job)
        else:
            print(job['name']+ ' ' + str(elapsed))

main()

Submission status: Wrong Answer

Solution code:
n, q = [ int( val ) for val in input( ).split( " " ) ]
ps = [0]*n
t = [0]*n
for i in range( n ):
	ps[i], t[i] = input( ).split( " " )


output = []
qsum = 0
while t:
	psi = ps.pop( 0 )
	ti = int( t.pop( 0 ) )
	if ti <= q:
		qsum += ti	
		output.append( psi+" "+str( qsum ) )
	else:
		t.append( ti - q )
		ps.append( psi )
		qsum += q

Submission status: Wrong Answer

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

cnt=0
while True:
	time=0
	for k,v in sorted(dict.items()):
		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+=100
	if time==n: break

Submission status: Wrong Answer

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

cnt=0
while True:
	time=0
	for k,v in sorted(dict.items()):
		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: Wrong Answer

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
time=0
while True:
	for k in kl:
		if dict[k]<=p:
			cnt+=dict[k]
			dict[k]=0
			print k,cnt
			del dict[k]
			kl.remove(k)
			time+=1
		else:
			dict[k]-=p
			cnt+=p
	if time==n: break

Submission status: Wrong Answer

Solution code:
N_str, q_str = raw_input().split()
N = int(N_str)
q = int(q_str)

A = []
for i in range(N):
    a = raw_input().split()
    A.append([a[0], int(a[1])])

total_time = 0
B = []
while A:
    name, time = A.pop(0)
    if time < q:
        total_time += time 
        B.append("%s %d" % (name, total_time))
    else:
        time -= q
        A.append([name, time])
        total_time += q
print '\n'.join(B)

Submission status: Wrong Answer

Solution code:
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
    
class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val()

s = input()
n,limit=map(int,s.split())
que=Queue()
for i in range(n):
    lis=input().split()
    que.enqueue((lis[0],int(lis[1])))

time=0
while(True):
    elm=que.dequeue()
    if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=100
    else:
        time+=elm[1]
        print(elm[0],time)

Submission status: Wrong Answer

Solution code:
class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

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

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1)

p_queue = Queue()
e_time = 0
ans = ""

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

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

while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        ans += "{0} {1}\n".format(process[0], process[1])
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process)

print(ans, end = "")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
"""
ラウンドロビンスケジューリングをシュミレートするプログラムを作成してください
"""
n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, time = input().split()
    q_list.append([name, int(time)])

time, conti = 0, 0 #timeは求める時間で contiはすべての要素が0になったことを確認するためのもの
while conti != n:
    if q_list[0][1] == 0:
        q_list.rotate(-1)
        conti += 1
    elif q_list[0][1] == 100:
        time += 100
        print (q_list[0][0], time)
        q_list[0][1] = 0
        conti += 1
    elif q_list[0][1] < 100:
        time += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], time)
        conti = 0
    else:
        q_list[0][1] -= 100
        time += 100
        q_list.rotate(-1)
        conti = 0

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
"""
ラウンドロビンスケジューリングをシュミレートするプログラムを作成してください
"""
n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, tm = input().split()
    q_list.append([name, int(tm)])

tm = 0 #tmは求める時間
while q_list:
    if q_list[0][1] == 0:
        q_list.popleft()
    elif q_list[0][1] == 100:
        tm += 100
        print (q_list[0][0], tm)
        q_list[0][1] = 0
    elif q_list[0][1] < 100:
        tm += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], tm)
    else:
        q_list[0][1] -= 100
        tm += 100
        q_list.rotate(-1)

Submission status: Wrong Answer

Solution code:
import collections

n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, time = input().split()
    q_list.append([name, int(time)])

time = 0
while q_list:
    if q_list[0][1] == 0:
        q_list.popleft()
    elif q_list[0][1] == 100:
        time += 100
        print (q_list[0][0], time)
        q_list[0][1] = 0
    elif q_list[0][1] < 100:
        time += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], time)
    else:
        q_list[0][1] -= 100
        time += 100
        q_list.rotate(-1)

Submission status: Wrong Answer

Solution code:
import collections

n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, time = input().split()
    q_list.append([name, int(time)])

time = 0 
while q_list:
    if q_list[0][1] == 0:
        q_list.popleft()
    elif q_list[0][1] == 100:
        time += 100
        print (q_list[0][0], time)
        q_list[0][1] = 0
    elif q_list[0][1] < 100:
        time += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], time)
    else:
        q_list[0][1] -= 100
        time += 100
        q_list.rotate(-1)

Submission status: Wrong Answer

Solution code:
import collections
n, q = map(int, input().split())
q_list = collections.deque()
for i in range(n):
    name, time = input().split()
    q_list.append([name, int(time)])

time = 0
while q_list:
    if q_list[0][1] == 0:
        q_list.popleft()
    elif q_list[0][1] == 100:
        time += 100
        print (q_list[0][0], time)
        q_list[0][1] = 0
        q_list.rotate(-1)
    elif q_list[0][1] < 100:
        time += q_list[0][1]
        q_list[0][1] = 0
        print (q_list[0][0], time)
        q_list.rotate(-1)
    else:
        q_list[0][1] -= 100
        time += 100
        q_list.rotate(-1)

Submission status: Wrong Answer

Solution code:
class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1

if __name__ == '__main__':
    n, q = [int(x) for x in raw_input().split()]
    ps_list = []
    for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

    queue = Queue(ps_list)
    print ps_list

    n_end_process = 0
    acc_time = 0
    while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += 100
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - 100)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
  
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i]

Submission status: Wrong Answer

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


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        print process_name
        print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
    print "--"
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i]

Submission status: Wrong Answer

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


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))

    print "--"
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i]

Submission status: Wrong Answer

Solution code:
class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0)

class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime)


def rr(queue):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > 100:
            task.time -= 100
            time += 100
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task)

if __name__ == '__main__':
    nq = [int(s) for s in input().split()]
    N = nq[0]
    q = nq[1]
    queue = Queue()
    task_arr = [Task(*input().split()) for i in range(N)]
    for t in task_arr:
        queue.enqueue(t)
    rr(queue)

Submission status: Wrong Answer

Solution code:
from collections import deque

process = deque(maxlen=10000)
n, q = [int(x) for x in input().split(' ')]

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

total_time = 0

while process:
    p_q = process.popleft()
    if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time))

Submission status: Wrong Answer

Solution code:
n,q=map(int,raw_input().split())

lst = []
for idx in xrange(n):
    name, time = raw_input().split()
    lst.append([name, int(time)])

idx = 0
tot = 0
while True:
  lst[idx][1] = lst[idx][1] - q
  if lst[idx][1] <= 0:
    tot += q + lst[idx][1]
    lst[idx][1] = 0
    print "%s %d" % (lst[idx][0], tot)
    lst.pop(idx)
    if len(lst)==0:
        break
  else:
    tot += q
    idx+=1
  if (idx >= len(lst)):
    idx = 0




    for idx in xrange(len(lst)):
        if lst[idx][1] == 0:
            continue
        lst[idx][1] = lst[idx][1] - q
        if lst[idx][1] <= 0:
           tot += q + int(lst[idx][1])
           lst[idx][1] = 0
           print "%s %d" % (lst[idx][0], tot)
           #print "1 rem=%d idx=%d lst[idx][1]=%d tot=%d" % (rem, idx, lst[idx][1], tot)
        else:
           tot += q
           rem = 0
           # print "2 rem=%d idx=%d lst[idx][1]=%d tot=%d" % (rem, idx, lst[idx][1], tot)
    flg = False
    for l in lst:
        if l[1] != 0:
            flg = True
    if not flg:
        break

Submission status: Wrong Answer

Solution code:
class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value <= 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()

    #
    # elif value == 0:
    #     current_time += interval
    #     print my_queue.queue[my_queue.head % my_queue.length].name, current_time
    #     my_queue.dequeue()
    #     return current_time

    elif value > 0:
        current_time += interval
        name, time = my_queue.queue[my_queue.head % my_queue.length].time, \
                     my_queue.queue[my_queue.head % my_queue.length].time
        my_queue.dequeue()
        my_queue.enqueue(name, time)

    return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1

current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time)

Submission status: Wrong Answer

Solution code:
class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 10010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        self.queue[self.tail].name = name
        self.queue[self.tail].time = time
        self.tail = (self.tail + 1) % self.length

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        self.queue[self.head].name = ""
        self.queue[self.head].time = 0
        self.head = (self.head + 1) % self.length

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head].forward_time(interval)
    if value <= 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head].name, current_time
        my_queue.dequeue()

    elif value > 0:
        current_time += interval
        name, time = my_queue.queue[my_queue.head].name, \
                     my_queue.queue[my_queue.head].time
        my_queue.dequeue()
        my_queue.enqueue(name, time)

    return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1

current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time)

Submission status: Wrong Answer

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

import traceback


class MyQueue:
    def __init__(self, size):
        self.queue = [0 for i in range(size)]
        self.max_size = size
        self.head = 0
        self.tail = 0

    def initialize(self):
        self.head = self.tail = 0

    def is_empty(self):
        if self.head == self.tail:
            return True
        return False

    def is_full(self):
        if self.head == (self.tail + 1) % self.max_size:
            return True
        return False

    def enqueue(self, elm):
        try:
            if self.is_full():
                raise Exception
            self.queue[self.tail] = elm
            if self.tail + 1 == self.max_size:
                self.tail = 0
            else:
                self.tail += 1
            return self.queue
        except Exception:
            traceback.print_exc()

    def dequeue(self):
        try:
            if self.is_empty():
                raise Exception
            x = self.queue[self.head]
            if self.head + 1 == self.max_size:
                self.head = 0
            else:
                self.head += 1
            return x
        except Exception:
            traceback.print_exc()


def main(queue, n):
    total = 0
    while queue.head != queue.tail:
        q = queue.dequeue()
        process = q[0]
        time = int(q[1])
        time = time - n
        if 0 > time:
            tmp = 100 + time
            total += tmp
            print(process + " " + str(total))
        else:
            total += 100
            queue.enqueue((process, str(time)))


if __name__ == '__main__':
    n, q = [int(s) for s in input().split()]
    queue = MyQueue(n+1)
    for i in range(n):
        name, time = input().split()
        queue.enqueue((name, time))
    main(queue, q)

Submission status: Wrong Answer

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


class MyQueue:
    def __init__(self, size):
        self.queue = [0 for i in range(size)]
        self.max_size = size
        self.head = 0
        self.tail = 0

    def initialize(self):
        self.head = self.tail = 0

    def is_empty(self):
        if self.head == self.tail:
            return True
        return False

    def is_full(self):
        if self.head == (self.tail + 1) % self.max_size:
            return True
        return False

    def enqueue(self, elm):
        if self.is_full():
            raise Exception
        self.queue[self.tail] = elm
        if self.tail + 1 == self.max_size:
            self.tail = 0
        else:
            self.tail += 1
        return self.queue

    def dequeue(self):
        if self.is_empty():
            raise Exception
        x = self.queue[self.head]
        if self.head + 1 == self.max_size:
            self.head = 0
        else:
            self.head += 1
        return x


def main(queue, n):
    total = 0
    while queue.head != queue.tail:
        q = queue.dequeue()
        process = q[0]
        time = int(q[1])
        time = time - n
        if 0 > time:
            tmp = 100 + time
            total += tmp
            print(process + " " + str(total))
        else:
            total += 100
            queue.enqueue((process, str(time)))


if __name__ == '__main__':
    n, q = [int(s) for s in input().split()]
    queue = MyQueue(n+1)
    for i in range(n):
        name, time = input().split()
        queue.enqueue((name, time))
    main(queue, q)