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: 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 = []
    queue = Queue()
    current_time = 0

    for p in process:
       queue.enqueue(p)

    while queue.data:
        p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    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()

Submission status: Time Limit Exceeded

Solution code:
import time as ti


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

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 50005
        self.queue = [0] * self.length
        self.head = 0
        self.tail = 0

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

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

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

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        self.queue[self.head] = 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)
    value = my_queue.queue[my_queue.head].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
        my_queue.enqueue(my_queue.queue[my_queue.head])
        my_queue.dequeue()

    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(Process(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: Time Limit Exceeded

Solution code:
n,q = list(map(int, input().split()))
queue = []
for i in range(n):
    pair = input().split()
    queue.append( (pair[0], int(pair[1])))

time = 0
while queue != []:
    p,t = queue[0]
    queue = queue[1:]
    if t<=q:
        time += t
        print(p,time)
    else:
        time += q
        queue.append((p,t-q))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
p = []
t = i = 0
for i in range(n):
    c = input().split()
    c[1] = int(c[1])
    p.append(c)
left = n
while left:
    i = (i+1) % n
    if p[i][1] == 0:
        continue
    if p[i][1] <= q:
        t += p[i][1]
        p[i][1] = 0
        print(p[i][0], t)
        left -= 1
    else:
        p[i][1] -= q
        t += q

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
label = [0 for i in range(n)]
content = [0 for i in range(n)]
for i in range(n):
    label[i], content[i] = input().split()
    content[i] = int(content[i])
time = 0
count = 0

while True:
    for i in range(n):
        if content[i] == 0:
            i += 1
        elif 0 < content[i] <= q:
            time += content[i]
            content[i] = 0
            print(label[i]+" "+str(time))
            count += 1
        else:
            time += q
            content[i] = content[i] - q
    if count == n:
        break

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
label = [0 for i in range(n)]
content = [0 for i in range(n)]
for i in range(n):
    label[i], content[i] = input().split()
    content[i] = int(content[i])
time = 0
count = 0

while True:
    for i in range(n):
        if content[i] == 0:
            i += 1
        elif 0 < content[i] <= q:
            time += content[i]
            content[i] = 0
            print(label[i]+" "+str(time))
            count += 1
            i += 1
        else:
            time += q
            content[i] = content[i] - q
            i += 1
    if count == n:
        break

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
label = [0 for i in range(n)]
content = [0 for i in range(n)]
for i in range(n):
    label[i], content[i] = input().split()
    content[i] = int(content[i])
time = 0
count = 0

while True:
    for i in range(n):
        if content[i] == 0:
            i += 1
        elif content[i] > q:
            time += q
            content[i] = content[i] - q
            i += 1
        else:
            time += content[i]
            content[i] = 0
            print(label[i]+" "+str(time))
            count += 1
            i += 1
       
    if count == n:
        break

Submission status: Time Limit Exceeded

Solution code:
s = raw_input().split()
n = int(s[0])
q = int(s[1])

process_name = []
process_time = []
for x in xrange(n):
  ps = raw_input().split()
  process_name.append(ps[0])
  process_time.append(ps[1])

total_time = 0
while process_name != []:
  pn = process_name.pop(0)
  pt = process_time.pop(0)
  if pt <= q:
    total_time += pt
    print pn, pt
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt)

print total_time

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 20 20:19:33 2017

@author: syaga
"""

if __name__ == "__main__":
    n, q = map(int, input().split())
    a = []
    for i in range(n):
        b = input().split()
        b[1] = int(b[1])
        a.append(b)
    ans = []
    time = 0
    flag = 0
    while True:
        if flag == 1:
            break
        for i in range(len(a)):
            if a[i] == []:
                continue
            if a[i][1] <= q:
                time += a[i][1]
                ans.append([a[i][0], time])
                a[i] = []
                if len(ans) == len(a):
                    flag = 1
                    break
            else:
                a[i][1] -= q
                time += q
    for i in ans:
        print(" ".join(map(str, i)))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
      S = (input()).split()
      n = int(S[0])
      q = int(S[1])
      head = 0
      tail = n-1
      que = []
      runtime = 0
      totaltime = 0
      fin = []
      for i in range(0, n):
            que.append((input()).split())
            totaltime = totaltime + int((que[i])[1])
      while runtime < totaltime:
            # now job
            nowjob = que[head]
            jobtime = int(nowjob[1])
            if jobtime > q :
                  jobtime = jobtime - q
                  (que[head])[1] = jobtime
                  tail = head
                  head = (head + 1) % n
                  runtime = runtime + q
            else :
                  runtime = runtime + jobtime
                  if jobtime != 0:
                        fin.append([(que[head])[0], runtime])
                  (que[head])[1] = 0
                  head = (head + 1) % n
      for i in range(0, n):
            print("{} {}".format((fin[i])[0], (fin[i])[1]))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item

queue = my_queue(queue)

time = 0
finish_task = []

while(queue != None):
    item = queue.dequeue()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.enqueue([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item

queue = my_queue(queue)

time = 0
finish_task = []

while(True):
    item = queue.dequeue()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.enqueue([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        #self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item

queue = my_queue(queue)

time = 0
finish_task = []

while(True):
    item = queue.dequeue()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.enqueue([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
queue = []
for _ in range(n):
    name, time = input().split()
    queue.append((name, int(time)))

finish_time = 0
while len(queue) > 0:
    name, time = queue[0]
    if q >= time:
        finish_time += time
        print('{} {}'.format(name, finish_time))
        queue = queue[1:]
    else:
        finish_time += q
        queue = queue[1:] + [(name, time - q)]

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
queue = []
for _ in range(n):
    name, time = input().split()
    queue.append((name, int(time)))

spend_time = 0
while len(queue) > 0:
    name, time = queue[0]
    tmp = min(q, time)
    spend_time += tmp
    time -= tmp
    if time == 0:
        print('{} {}'.format(name, spend_time))
        queue = queue[1:]
    else:
        queue = queue[1:] + [(name, time)]

Submission status: Time Limit Exceeded

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

queue = [input().split() for y in range(n)]
time = 0;

while True:
    if int(queue[0][1]) <= q:
        time += int(queue[0][1])
        print(queue[0][0], time)
        if len(queue) == 1:
            break
        queue.pop(0)
    else:
        time += q
        queue[0][1] = str(int(queue[0][1]) - q)
        queue = queue[1:] + queue[:1]

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
p=[]
for _ in[0]*n:
 s,k=input().split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  a=p[i]
  if b[i]:
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)

Submission status: Time Limit Exceeded

Solution code:
import sys
n,q=map(int,input().split())
p=[]
for e in sys.stdin:
 s,k=e.split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  a=p[i]
  if b[i]:
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)

Submission status: Time Limit Exceeded

Solution code:
import sys
n,q=map(int,input().split())
p=[]
for e in sys.stdin:
 s,k=e.split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  if b[i]:
   a=p[i]
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
m,p=[0],[0]
for _ in[0]*n:
 s,k=input().split()
 m+=[s]
 p+=[int(k)]
b=list(range(n+1))
t=0
while sum(b):
 for i in b:
  if p[i]>q:p[i]-=q;t+=q
  elif m[i]:b[i]=0;t+=p[i];print(m[i],t)

Submission status: Time Limit Exceeded

Solution code:
n, p = map(int, input().split())
ps = []
for i in range(n):
    ps.append(input().split())
    ps[i][1] = int(ps[i][1])
t = 0
i = 0
j = 0
while j < n:
    if ps[i][1] > p:
        ps[i][1] -= p
        t += p
    elif ps[i][1] != 0:
        t += ps[i][1]
        ps[i][1] = 0
        print("{0} {1}".format(ps[i][0], t))
        j += 1
    i = (i + 1) % n

Submission status: Time Limit Exceeded

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] == 0:
        i += 1
        if i == n:
            i = 0
        continue
    if time[i] <= q:
        current_time += time[i]
        finished.append(name[i])
        fin_time.append(current_time)
        time[i] = 0
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i += 1
        if i == n:
            i = 0

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

Submission status: Time Limit Exceeded

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] == 0:
        i = (i+1)%n
        continue
    if time[i] <= q:
        current_time += time[i]
        finished.append(name[i])
        fin_time.append(current_time)
        time[i] = 0
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%n

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
d=s.split()
n=int(d[0])
q=int(d[1])
end_t=0
processes=[]
for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1]))

cnt=0
i=0
while True:
    if processes[i][1]<=q:
       if processes[i][1]==0:
           i=(i+1)%n
           continue
       end_t+=processes[i][1]
       processes[i][1]=0
       print(processes[i][0],end_t)
       i=(i+1)%n
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[i][1]-=q
       end_t+=q
       i=(i+1)%n

Submission status: Time Limit Exceeded

Solution code:
s=input()
d=s.split()
n=int(d[0])
q=int(d[1])
end_t=0
processes=[]
for i in range(n):
    processes.append([])
    s=input()
    d=s.split()
    processes[i].append(d[0])
    processes[i].append(int(d[1]))

cnt=0
i=0
while True:
    if processes[i][1]<=q:
       if processes[i][1]==0:
           i=(i+1)%n
           continue
       end_t+=processes[i][1]
       processes[i][1]=0
       print(processes[i][0],end_t)
       i=(i+1)%n
       cnt+=1
       if cnt==n:
           break
   
    else:
       processes[i][1]-=q
       end_t+=q
       i=(i+1)%n

Submission status: Time Limit Exceeded

Solution code:
from collections import namedtuple

Task = namedtuple('Task', 'name time')

class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def enqueue(self, x):
        if self.isFull():
            raise IndexError("queue is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[1]
            for i in range(1, self._top):
                self._l[i] = self._l[i+1]
            self._l[self._top] = None
            self._top -= 1
            return e

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

    def isFull(self):
        return self._top == self.n

if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
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 = queue[1:]
        print("{} {}".format(name, t))
    else:
        queue = queue[1:] + \
            [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
        t += q

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
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 = queue[1:]
        print("{} {}".format(name, t))
    else:
        if len(queue) != 1:
            queue = queue[1:] + \
                [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
            t += q
        else:
            queue[0] = {"name": queue[0]["name"], "time": queue[0]["time"] - q}
            t += q

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
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: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
class Process(object):
    def __init__(self, name, s):
        self.name = name
        self.s = s

    def exec(self, q):
        t = 0
        for _ in range(q):
            t += 1
            q -= 1
            self.s -= 1
            if self.s == 0 or q == 0:
                return t

def execute(processes, q):
    time = 0
    completed = []
    while len(processes) != len(completed):
        for i, p in enumerate(processes):
            if not p.s == 0:
                time += p.exec(q)
                if p.s == 0:
                    completed.append((p, time))
    return completed

def run():
    n, q = list(map(int, input().split()))
    processes = []
    for _ in range(n):
        name, time = input().split()
        processes.append(Process(name, int(time)))
    completed = execute(processes, q)
    for c in completed:
        print(c[0].name, c[1])

if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
class Process(object):
    def __init__(self, name, s):
        self.name = name
        self.s = s

    def exec(self, q):
        if self.s <= q:
            time = self.s
            self.s = 0
            return time
        else:
            time = q
            self.s = self.s - q
            return time

def execute(processes, q):
    time = 0
    completed = []
    while len(processes) != len(completed):
        for i, p in enumerate(processes):
            if not p.s == 0:
                time += p.exec(q)
                if p.s == 0:
                    completed.append((p, time))
    return completed

def run():
    n, q = list(map(int, input().split()))
    processes = []
    for _ in range(n):
        name, time = input().split()
        processes.append(Process(name, int(time)))
    completed = execute(processes, q)
    for c in completed:
        print(c[0].name, c[1])

if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	i %= n
	a = que[i]
	if 0 < a[1] <= q:
		t += a[1]
		que[i][1] = 0
		print a[0],t				
	elif q < a[1]:
		t += q
		que[i][1] = a[1] - q
	i += 1

Submission status: Memory Limit Exceeded

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

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 1000100
        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()
        return current_time

    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
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.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: Accepted

Solution code:
#----------------for input------------------------
numberAndQuontum=input().split()
number=int(numberAndQuontum[0])
Quontum=int(numberAndQuontum[1])
allProcessList=[]

index=0
while index<number:
    nameAndTime=input().split()
    nameTimeList=[]
    nameTimeList.append(nameAndTime[0])
    nameTimeList.append(int(nameAndTime[1]))
    allProcessList.append(nameTimeList)
    index+=1
#----------------for input------------------------

def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main---------------------------
schedule(Quontum,allProcessList)