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: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
d = deque()
for i in range(n):
    tmp = input().split()
    tmp[1] = int(tmp[1])
    d.append(tmp)
time = 0
while len(d) > 0:
    tmp = d.popleft()
    time += min(q, tmp[1])
    if tmp[1] > q:
        tmp[1] -= q
        d.append(tmp)
    else:
        print(tmp[0] + ' ' + str(time))

Submission status: Accepted

Solution code:
#  queue
#  round-robin-scheduler

class Process:
    name = ""
    time = 0

    def __init__(self,name,time):
        self.name = name
        self.time = time


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

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

time_in_now = 0
while queue:
    if queue[0].time > q:
        queue[0].time -= q
        time_in_now += q
        temp = queue[0]
        queue.pop(0)
        queue.append(temp)
    else:
        time_in_now += queue[0].time
        print(f"{queue[0].name} {time_in_now}")
        queue.pop(0)

Submission status: Accepted

Solution code:
n,q = map(int,input().split())
my_list = [input().split() for s in range(n)]
count = 0
while my_list != []:
    a = my_list.pop(0)
    n1 = a[0]
    n2 = int(a[1])
    if n2 > q:
        n2 -= q
        count += q
        my_list.append([n1,n2])
    else:
        count += n2
        print(n1,count)

Submission status: Accepted

Solution code:
class Queue():
    def __init__(self):
        self.queue = [None] * 100000
        self.head = 0
        self.tail = 0
        self.max_queue = len(self.queue)

    def is_empty(self):
        return self.head == self.tail

    def is_full(self):
        return self.head == (self.tail + 1) % self.max_queue

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("Error: Full!")

        self.queue[self.tail] = x

        if self.tail + 1 == self.max_queue:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("Error: Empty!")

        x = self.queue[self.head]

        if self.head + 1 == self.max_queue:
            self.head = 0
        else:
            self.head += 1
        return x


process_name = Queue()
process_cost = Queue()

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

for i in range(n):
    name, time = input().split()
    time = int(time)

    process_name.enqueue(name)
    process_cost.enqueue(time)

at_time = 0
while not process_name.is_empty():
    name = process_name.dequeue()
    cost = process_cost.dequeue()
    if cost > q:
        process_name.enqueue(name)
        process_cost.enqueue(cost - q)
        at_time += q
    else:
        at_time += cost
        print(f"{name} {at_time}")
        pass

    pass

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
que = deque()
for _ in range(n):
	for x in input().split():
		if (x.isdigit()):
			que.append(int(x))
		else:
			que.append(x)
t = 0
while que:
	name = que.popleft()
	lefttime = que.popleft()
	if (lefttime <= q):
		t += lefttime
		print(name, t)
	else:
		t += q
		lefttime -= q
		que.append(name)
		que.append(lefttime)

Submission status: Accepted

Solution code:
import collections
d = collections.deque([])
n, p = map(int, input().split())
for i in range(n):
    name, t = input().split()
    d.append((name, int(t)))
tt = 0
while len(d) > 0:
    name, t = d.popleft()
    if t <= p:
        tt += t
        print("{0} {1}".format(name, tt))
    elif t > p:
        t = t - p
        tt += p
        d.append((name, t))

Submission status: Accepted

Solution code:
# ライブラリのインポート
#import re #正規表現
#import sys
#import heapq
import collections


def main():
    n, q = map(int, input().split())
    deq = collections.deque()
    for i in range(n):
        name, time = input().split()
        deq.append((int(time),name))
    ans = []
    elps = 0
    while deq:
        time, name = deq.popleft()
        if time <= q:
            elps += time
            ans.append((name, elps))
        else:
            elps += q
            deq.append((time-q, name))
    [print(*i) for i in ans]
    


    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


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

    def isEmpty(self):
        return len(self.Q) == 0

    def enqueue(self, x):
        self.Q.append(x)
        # return self.Q

    def dequeue(self):
        if self.isEmpty():
            sys.exit("Empty")
        else:
            return self.Q.pop(0)



n, power = map(int, raw_input().split(" "))
process_list = [map(str, raw_input().split(" ")) for i in range(n)]
process_list = [(p[0], int(p[1])) for p in process_list]

q = Queue()
for p in process_list:
    q.enqueue(p)
elapsed_time = 0
while not q.isEmpty():
    process = q.dequeue()
    if process[1] > power:
        elapsed_time += power
        q.enqueue((process[0], process[1] - power))
    else:
        elapsed_time += process[1]
        print(str(process[0]) + " " + str(elapsed_time))

Submission status: Accepted

Solution code:
from collections import deque

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

que = deque()

for _ in range(n):
	s, t = input().split()
	t = int(t)
	que.append((s, t))

t = 0
while len(que)>0:
	name, time = que.popleft()
	if time<=q:
		t += time
		print("{} {}".format(name,t))
	else:
		que.append((name, time-q))
		t += q

Submission status: Accepted

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

class Process:
  def __init__(self, name, time):
    self.name = name
    self.time = time

class Queue:
  def __init__(self, length):
    self.q = [Process('p0', 0)]*length
    self.MAX = length
    self.head = 0
    self.tail = 0
  
  def enqueue(self, x):
    self.q[self.tail] = x
    if self.tail+1 == self.MAX:
      self.tail = 0
    else:
      self.tail += 1 
  
  def dequeue(self):
    x = self.q[self.head]
    if self.head + 1 == self.MAX:
      self.head = 0
    else: 
      self.head += 1
    return x
  
  def isEmpty(self):
    if self.head == self.tail:
      return True
    else:
      return False

  def isFull(self):
    if self.head == (self.tail+1)%self.MAX:
      return True
    else:
      False


Q = Queue(100000) 

for _ in range(n):
  x,y = map(str, input().split())
  tmp = Q.enqueue(Process(x,int(y)))

time = 0
while not Q.isEmpty():
  qtop = Q.dequeue()
  if qtop.time > qtm:
    time += qtm
    qtop.time -= qtm
    Q.enqueue(qtop) 
  else:
    time += qtop.time
    qtop.time = 0
    print(qtop.name + ' ' + str(time))

Submission status: Accepted

Solution code:
import collections


num_proc, quantum = tuple(map(int, input().split(' ')))
proc_list = collections.deque()

for i in range(0, num_proc):
    proc_elem = input().split(' ')
    proc_elem[1] = int(proc_elem[1])
    proc_list.append(proc_elem)

timer = 0
while bool(proc_list):
    if proc_list[0][1] <= quantum:
        timer += proc_list[0][1]
        print(f'{proc_list.popleft()[0]} {timer}')
    else:
        timer += quantum
        proc_list[0][1] -= quantum
        proc_list.append(proc_list.popleft())

Submission status: Accepted

Solution code:
queue = []

def enqueue(obj):
  queue.append(obj)

def dequeue():
  v = queue[0]
  del queue[0]

  return v

n, q = map(int, input().split())
for i in range(n):
  p, t = input().split()
  queue.append({"p": p, "t": int(t)})

sum_t = 0
while len(queue) > 0:
  v = dequeue()
  c = min(v["t"], q)
  sum_t += c
  v["t"] -= c
  if v["t"] > 0:
    enqueue(v)
  else:
    print (v["p"], sum_t)

Submission status: Accepted

Solution code:
from collections import deque

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

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

sum_time=0
while len(que)>0:
    if que[0][1]-q<=0:
        sum_time+=que[0][1]
        print(que[0][0],sum_time)
        que.popleft()
    else:
        sum_time+=q
        que[0][1]-=q
        que.append(que.popleft())

Submission status: Accepted

Solution code:
global Q
global N
def deque():
    global head
    x=Q[1][head]
    if head+1==maxn:
        head=0
    else:
        head=head+1
    return x
def enque(i,a):
    global tail
    Q[0][tail]=Q[0][i]
    Q[1][tail]=a
    if tail+1==maxn:
        tail=0
    else:
        tail=tail+1
n,q=map(int,input().split())
Q=[[0 for j in range(n)] for i in range(2)]
N=[[0 for j in range(n)] for i in range(2)]
head=0
tail=0
for i in range(0,n):
    a,b=input().split()
    Q[0][i]=a
    Q[1][i]=(int(b))
maxn=n
i=0
k=0
time=0
while 1:
    if Q[1][i]>q:
        time=time+q
        l=deque()-q
        enque(i,l)
        i=i+1
        if i==maxn:
            i=0
    else:
        time=time+deque()
        N[0][k]=Q[0][i]
        N[1][k]=time
        i=i+1
        if tail==head and k==n-1:
            time=time+Q[1][head]
            break
        if i==maxn:
            i=0
        k=k+1
for i in range(0,n):
    print(N[0][i],end=" ")
    print(N[1][i])

Submission status: Accepted

Solution code:
answer = []
n, q = [int(i) for i in input().split(" ")]
for i in range(n):
    name, time = input().split(" ")
    time = int(time)
    answer.append([name, time])

time = 0
while len(answer) > 0:
    p = answer.pop(0)
    if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        p[1] -= q
        time += q
        answer.append(p)

Submission status: Accepted

Solution code:
from collections import deque

N,q=map(int,input().split())
Q=deque()
#deque型はデータをキューやスタック、デックとして効率的に扱うことができる

for i in range(N):
    name,time=input().split()
    Q.append([name,int(time)])

sum=0

while Q:
    
    qt = Q.popleft()
    #print(qt)
    if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt)

Submission status: Accepted

Solution code:
class Queue:
    def __init__(self):
        self.queue = []
    def push(self, x):
        self.queue.append(x)
    def pop(self):
        return self.queue.pop(0)
    def isEmpty(self):
        return len(self.queue) == 0

n, q = list(map(int, input().split(' ')))
process_queue = Queue()
for i in range(n):
    name, time = list(input().split(' '))
    process_queue.push([name, int(time)])

total_time = 0
while True:
    name, time = process_queue.pop()
    if time <= q:
        print('{} {}'.format(name, time + total_time))
        add_time = time
    else:
        time -= q
        process_queue.push([name, time])
        add_time = q
    total_time += add_time
    if process_queue.isEmpty():
        break

Submission status: Accepted

Solution code:
from collections import deque
robin=deque()

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

for i in range(n):
    p,t=input().split()
    robin.append([p,int(t)])

time=0
while(len(robin)!=0):
    proc=robin.popleft()
    if(proc[1]<=q):
        print(proc[0],time+proc[1])
        time+=proc[1]
    else:
        proc[1]-=q
        robin.append(proc)
        time+=q

Submission status: Accepted

Solution code:
from collections import deque

def main():
    
    # input & initialize
    n, q = map(int, input().split())

    total_time = 0

    dname = deque()
    dtime = deque()

    for i in range(n):
        nametmp, timetmp = input().split()
        dname.append(nametmp)
        dtime.append(int(timetmp))
    
    while dname or dtime: # queueになにか入っていればTrue
        name = dname.popleft()
        time = dtime.popleft()
        if time <= q: # q以下だったら除外
            total_time += time
            print(name, total_time)
        else: # q以上だったらtime減らしてFIFOに戻す
            total_time += q
            time -= q
            dname.append(name)
            dtime.append(time)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import queue

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

N, Q = list(map(int, input().split()))

q = queue.Queue()

for _ in range(N):
    name, time = input().split()
    item = Process(name, int(time))
    q.put(item)

time_sum = 0
while not q.empty():
    pop = q.get()
    if pop.time > Q:
        pop.time = pop.time - Q
        time_sum += Q
        q.put(pop)
    else:
        time_sum += pop.time
        print(pop.name, time_sum)

Submission status: Accepted

Solution code:
from collections import deque

n,q=[int(i) for i in input().split()]
que = deque()
for a in range(n):
    s = input().split()
    que.append((s[0], int(s[1])))

t = 0
done = []
while len(que) != 0:
    name, time = que.popleft()
    mi = min(q, time)
    t += mi
    time -= mi
    if time == 0:
        done.append((name, t))
    else:
        que.append((name, time))
for a in done:
    print(a[0], a[1])

Submission status: Accepted

Solution code:
from queue import Queue
# from queue import LifoQueue as Stack


N,q = list(map(int,input().split()))

Q=Queue()
for i in range(N):
    Q.put(list(map(str,input().split())))


ans=[]

time=0
while len(ans)!=N:
    p,t=Q.get()
    t=int(t)
    if t-q>0:
        Q.put([p,str(t-q)])
        time+=q
    else:
        time+=t
        ans.append((p,time))

for p,t in ans:
    print(p,t)

Submission status: Accepted

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

LEN = 100005
process_list = [None] * LEN
head = 1
tail = n + 1
elaps = 0

class Process:
    def __init__(self, name, time):
        self.name = name
        self.t = time
        
def enqueue(x):
    global process_list, tail
    process_list[tail] = x
    tail = (tail + 1) % LEN
    
def dequeue():
    global process_list, head
    x = process_list[head]
    head = (head + 1) % LEN
    return x
    
def min(a, b):
    a = int(a)
    b = int(b)
    return a if a <= b else b

for i in range(1, n + 1):
    input_list = list(input().split())
    name, time = input_list
    process_list[i] = Process(name, time)

# start simulationing
while head != tail:
    u = dequeue()
    c = min(q, u.t)
    u.t = int(u.t) - c
    elaps += c
    if int(u.t) > 0:
        enqueue(u);
    else:
        print('{} {}'.format(u.name, elaps))

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
x = []
for i in range(0, n):
    x.append(list(input().split()))
    x[-1][1] = int(x[-1][1])

que = deque(x)
time = 0

while len(que) > 0:
    y = que.popleft()
    if y[1] <= q:
        time = time + y[1]
        print(y[0], time)
    else:
        time = time + q
        y[1] = y[1] - q
        que.append(y)

Submission status: Accepted

Solution code:
n, q = map(int, input().split(' '))
names = []
rest_time_table = {}
for _ in range(n):
    name_time = input().split(' ')
    name, time = name_time[0], int(name_time[1])
    names.append(name)
    rest_time_table[name] = time

total_time = 0
while True:
    if len(names) == 0:
        break
    name = names.pop(0)
    time = rest_time_table[name]
    rest_time = time - q
    if rest_time <= 0:
        total_time += time
        print(name, total_time)
        continue
    rest_time_table[name] = rest_time
    total_time += q
    names.append(name)

Submission status: Accepted

Solution code:
from collections import deque, namedtuple


class Process(object):
    def __init__(self, name, time):
        self.name = name
        self.time = time


def main():
    n, quantum = [int(i) for i in input().split()]
    queue = deque([Process(i, int(j)) for _ in range(n) for (i, j) in [input().split()]])
    completed = []
    time = 0
    while queue:
        processing = queue.popleft()
        delta_time = min(processing.time, quantum)
        processing.time -= delta_time
        time += delta_time
        if processing.time == 0:
            completed.append(Process(processing.name, time))
        else:
            queue.append(processing)
    for process in completed:
        print(process.name, process.time)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
listA = []
t=1
while t <=n:
    try:
        listA.append(input().split())
        t +=1
    except:
        break

result=[]
qu = deque()
for i in range(n):
    qu.append(listA[i])

time = 0
while True:
    try:
        task = qu.popleft()
        if int(task[1]) <= q:
            time += int(task[1])
            result.append([task[0], time])
        else:
            time += q
            task[1] = int(task[1]) - q
            qu.append(task)
    except:
        break


for i in range(n):
    print(*result[i])

Submission status: Accepted

Solution code:
a = input().split()
n = int(a[0])
q = int(a[1])
listn = []
listt = []
anslistn = []
anslistt = []
keika = int(0)

for i in range(n):
	a = input().split()
	listn.append(a[0])
	listt.append(int(a[1]))

while listt: 
	num = listt.pop(0) - q
	keika += q
	if num > 0:
		listt.append(num)
		listn.append(listn.pop(0))
	else:
		keika += num
		anslistn.append(listn.pop(0))
		anslistt.append(keika)

i = int(0)

for i in range(n):
	print(str(anslistn[i]) + ' ' + str(anslistt[i]))

Submission status: Accepted

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

  def getName(self):
    return self.name

  def getTime(self):
    return self.time

  def runTask(self, q):
    if(self.time > q):
      self.time -= q
      return q
    else:
      tempTime = self.time
      self.time = 0
      return tempTime

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

retAry = []
qTime = 0
que = []

for i in range(n):
  name, time = input().split()
  process = Process(name, int(time))
  que.append(process)

while(len(que)):
  process = que.pop(0)

  qTime += process.runTask(q)
  if(process.getTime() != 0):
    que.append(process)
  else:
    retAry.append(process.getName() + ' ' + str(qTime))

for i in range(len(retAry)):
  print(retAry[i])

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
name = deque()
time = deque()
for i in range(n):
    p, t = input().split(" ")
    name.append(p)
    time.append(int(t))

fin_time = 0
while (time):
    temp_time = time.popleft()
    temp_name = name.popleft()
    fin_time += min(q, temp_time)
    if q >= temp_time:
        print(temp_name + ' ' + str(fin_time))
    else:
        temp_time -= q
        time.append(temp_time)
        name.append(temp_name)

Submission status: Accepted

Solution code:
from collections import deque

n,q=list(map(int,input().split()))
nt=deque()
for i in range(n):
  nt.append(input().split())
  nt[i][1]=int(nt[i][1])
t=0
while len(nt) > 0:
  if nt[0][1] <= q:
    t += nt[0][1]
    print(str(nt[0][0]) + " " + str(t))
    nt.popleft()  
  else:  
    nt[0][1]=nt[0][1]-q
    nt.rotate(-1)
    t += q

Submission status: Accepted

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

consumed_time = 0
completed_tasks = []
while True:
    try:
        n_qt = queue.pop(0)
    except:
        break

    name, qtime = n_qt
    if qtime <= q:
        consumed_time += qtime
        completed_tasks.append((name, consumed_time))
    else:
        qtime -= q
        consumed_time += q
        queue.append((name, qtime))

for name, t in completed_tasks:
    print(name, t)

Submission status: Accepted

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

progress = 0

while A:
    if A[0][1] <= q:
        progress += A[0][1]
        print(A[0][0], progress)
        A.pop(0)
    else:
        progress += q
        A[0][1] -= q
        A += [A[0]]
        A.pop(0)

Submission status: Accepted

Solution code:
class Process():

    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])
        self.endtime = 0

    def process(self, time):
        process_time = min(time, self.time)
        self.time -= process_time
        return process_time

    def is_done(self):
        return self.time <= 0


class MyQueue():

    def __init__(self, max):
        self.Q = [None for _ in range(max)]
        self.head = 0
        self.tail = 0
        self.max = max

    def enqueue(self, x):
        if self.is_full():
            raise ValueError
        self.Q[self.tail] = x
        self.tail += 1
        if self.tail == self.max:
            self.tail = 0

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        ret = self.Q[self.head]
        self.head += 1
        if self.head == self.max:
            self.head = 0
        return ret

    def is_empty(self):
        return self.head == self.tail

    def is_full(self):
        return self.head == (self.tail + 1) % self.max

def main():
    n, q = map(int, input().split())
    queue = MyQueue(n + 1)
    current_time = 0
    done = []
    [queue.enqueue(Process(input().split())) for i in range(n)]

    while True:
        try:
            p: Process = queue.dequeue()
        except IndexError:
            break
        process_time = p.process(q)
        current_time += process_time
        if p.is_done():
            p.endtime = current_time
            done.append(p)
        else:
            queue.enqueue(p)

    [print(p.name, p.endtime, sep=" ") for p in done]

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]

process_list = []
result_list = []

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

now_time = 0
while process_list != []:
    #print(process_list)
    [name, time] = process_list.pop(0)
    if time <= q:
        now_time += time
        result_list.append([name, now_time])
    else:
        now_time += q
        process_list.append([name, time-q])

for r in result_list:
    print(r[0]+' '+str(r[1]))

Submission status: Accepted

Solution code:
from collections import deque

N, Q = map(int, input().split())
names = []
tasks = []

for i in range(N):
    name, task = input().split()
    names.append(name)
    tasks.append(int(task))

names_q = deque(names)
task_q = deque(tasks)

time = 0
while(len(task_q) > 0):
    name = names_q.popleft()
    task = task_q.popleft()
    if task <= Q:
        time += task
        print(name, time)
    else:
        time += Q
        task -= Q
        names_q.append(name)
        task_q.append(task)

Submission status: Accepted

Solution code:
# ALDS1_3_B: Queue
n, q = list(map(int, input().split()))
data = [input().split() for _ in range(n)]
total_time = 0
ends = []
for name, time in data:
    time = int(time)
    total_time += q if time - q > 0 else time
    time = time - q
    if time > 0:
        data.append([name, time])
        continue
    ends.append([name, total_time])

for name, time in ends:
    print(name, time)

Submission status: Accepted

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

A = []

for i in range(n):
  A.append(input())

i = 0

time = 0

while not A == []:
  x,y = map(str, A[i].split())
  y = int(y)
  if y <= q:
    time += y
    times = str(time)
    A[i] = x + " " + times
    print(A.pop(i))
  else:
    z = y-q
    z = str(z)
    time += q
    A.append(x + " " + z)
    del A[i]

Submission status: Accepted

Solution code:
class MyQueue():
    def __init__(self):
        self.queue = []
    def enqueue(self, item):
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) == 0:
            return None
        result = self.queue[0]
        del self.queue[0]
        return result

n, q = map(int, input().split())
name = [0] * n
time = [0] * n
for i in range(n):
    name[i], time[i] = input().split()


myqueue_name = MyQueue()
myqueue_time = MyQueue()
for i in range(n):
    myqueue_name.enqueue(name[i])
    myqueue_time.enqueue(int(time[i]))

count = 0
roop = 0
sum_time = 0
while count != n:
    x = myqueue_name.dequeue()
    y = myqueue_time.dequeue()
    if y <= q:
        count += 1 #抜けた数
        sum_time += y #yだけ加算
        print(x, sum_time)
    else:
        roop += 1
        sum_time += q #限界値
        myqueue_name.enqueue(x)
        myqueue_time.enqueue(y - q)

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
que = deque([])
for i in range(n):
    name, time = input().split()
    que.append({'name': name, 'time': int(time)})

past = 0
while len(que) > 0:
    np = que.popleft()
    if q < np['time']:
        np['time'] = np['time'] - q
        que.append(np)
        past += q
    else:
        past += np['time']
        print(np['name'], past)

Submission status: Accepted

Solution code:
from collections import deque
n,qms = map(int, input().split())

que = deque([])
for i in range(n):
    name, value = input().split() # まずはデータを取り出して、それをDequeに入れこむ
    value = int(value)
    que.append([name,value])
i,t = 0,0

while len(que)>0:
    if que[0][1] > qms:
        name_rest,value_rest =que[0][0], que[0][1] - qms
        que.popleft()
        que.append([name_rest,value_rest])
        t += qms
    else:
        t += que[0][1]
        print(que[0][0],t)
        que.popleft()

Submission status: Accepted

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

total = 0

while len(queue) > 0:
    name, time = queue.pop(0)
    if time > q:
        total += q
        queue.append((name, time - q))
    else:
        total += time
        print(name, total)

Submission status: Accepted

Solution code:
class Process:

    def __init__(self, name, time):
        self.name = name
        self.time = time

    def execute(self, q):
        if self.time == 0:
            raise RuntimeError
        execution_time = min(self.time, q)
        self.time -= execution_time
        return execution_time

    def is_ended(self):
        return self.time == 0


class Queue:

    def __init__(self):
        self.head = 0
        self.tail = 0
        self.queue = [0] * 100005

    def is_empty(self):
        return self.head == self.tail

    def is_full(self):
        return self.head == (self.tail + 1) % len(self.queue)

    def enqueue(self, x):
        self.queue[self.tail] = x
        if self.tail + 1 == len(self.queue):
            self.tail = 0
        else:
            self.tail += 1

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


def main():
    # input
    n, q = list(map(int, input().split(' ')))
    processes = []
    for _ in range(n):
        name, time = input().split(' ')
        processes.append(Process(name, int(time)))
    Q = Queue()
    for process in processes:
        Q.enqueue(process)

    # execute
    elapsed_time = 0
    while not Q.is_empty():
        process = Q.dequeue()
        elapsed_time += process.execute(q)
        if process.is_ended():
            print(process.name, elapsed_time)
        else:
            Q.enqueue(process)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

class Queue:
    def __init__(self, n):
       
        self.head = 0
        self.tail = 0
        self.MAX = 100005
        self.queue = [Process()] * self.MAX 
        self.qtime = 0
        
    def isEmpty(self):
        return self.head == self.tail
        
    def isFull(self):
        return ( self.queue[self.tail].name != "" ) and (self.head == (self.tail + 1) % self.MAX ) 

    def enqueue(self, x):
        if self.isFull():
            print("error: overflow")
        self.queue[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1
        
    def dequeue(self):
        if self.isEmpty():
            print("error: underflow")
            return
        
        x = self.queue[self.head]
        
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x
        
class Process:
    def __init__(self, name = "", time = 0):
        self.name = name
        self.time = time
        
        


tmpList = list(input().split())
N = int(tmpList[0])
qTime = int(tmpList[1])
Q = Queue(N)
Q.qtime = qTime
for i in range(N):
    tmpList = list(input().split())
    tmpProcess = Process(tmpList[0], int(tmpList[1]))
    #Q.queue[i] = tmpProcess
    Q.enqueue(tmpProcess)

cnt = 0
    
while Q.isEmpty() == False:
    process = Q.dequeue()
    
    if process.time > qTime:
        process.time -= qTime
        Q.enqueue(process)
        cnt += qTime
    else:
        cnt += process.time
        print(process.name ,cnt)

"""
    print(Q.head, Q.tail)
    if Q.queue[Q.head].time > qTime:
        Q.queue[Q.head].time -= qTime
    else:
        print(Q.queue[Q.head].name)
        Q.dequeue()
"""

Submission status: Accepted

Solution code:
from collections import deque as dq
n,q=map(int,input().split())
queue=dq([])
time=0
for i in range(n):
	a,b=input().split()
	queue.append([a,int(b)])
while queue:
	p=queue.popleft()
	if p[1]>q:
		p[1]-=q
		time+=q
		queue.append(p)
	else:
		time+=p[1]
		print(p[0],time)

Submission status: Accepted

Solution code:
n, q, *S = open(0).read().split()
q = int(q)
J = list(zip(*[iter(S)]*2))
T = 0
while J:
    n, t = J.pop(0)
    t = int(t)
    if t <= q:
        T += t
        print(f'{n} {T}')
    else:
        T += q
        J.append((n, t-q))

Submission status: Accepted

Solution code:
from collections import deque

d = deque()
n = list(map(int, input().split()))
time = 0

for i in range(int(n[0])):
    p = input().split()
    p[1] = int(p[1])
    if p[1] <= n[1]:
        time += p[1]
        print(p[0], end=" ")
        print(time)
    else:
        p[1] -= n[1]
        time += n[1]
        d.append(p)

while len(d) != 0:
    pnew = d.popleft()
    if pnew[1] <= n[1]:
        time += pnew[1]
        print(pnew[0], end=" ")
        print(time)

    else:
        pnew[1] -= n[1]
        time += n[1]
        d.append(pnew)