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:
n, q = list(map(int, input().split(' ')))
input_ = [input().split(' ') for i in range(n)]
process = [{'name':input_[i][0], 'time':int(input_[i][1])} for i in range(n)]

time_table = 0
queue = [process[i] for i in range(n)]
while queue:
    tmp_pro = queue.pop(0)
    if tmp_pro['time'] > q:
        time_table += q
        tmp_pro['time'] -= q
        queue.append(tmp_pro)
    else:
        time_table += tmp_pro['time']
        print(tmp_pro['name'] + ' ' + str(time_table))

Submission status: Accepted

Solution code:
from collections import deque

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

que = []
for _ in range(n):
	que.append(input())
que.append("")
head=0
tail=n
cnt=0
result=[]
flag=1
#print(que,result,head,tail)
while head!=tail:
	temp=que[head].split()
	head=head+1
	if head>n:
		head=head-n-1
	if int(temp[1])<=q:
		cnt+=int(temp[1])
		result.append(temp[0]+" "+str(cnt))
	else:
		cnt+=q
		que[tail]=temp[0]+" "+str(int(temp[1])-q)
		tail+=1
		if tail>n:
			tail=tail-n-1
	#print(que,result,head,tail)

#print("#################")
for item in result:
	print(item)

Submission status: Accepted

Solution code:
n,q = map(int,input().split())
MAX = int(10**6)
A = [[0 for i in range(2)] for j in range(MAX)]
head = 0
end = int(n)-1
cnt = 0
for i in range(n):
    A[i][0],A[i][1] = input().split()

while 1:
    if head == end:
        print("{} {}".format(A[head][0],cnt+int(A[head][1])))
        break

    temp = A[head]
    head +=1
    if int(temp[1]) <= q:
        print("{} {}".format(temp[0],cnt+int(temp[1])))
        cnt += int(temp[1])
    else:
        temp[1] = str(int(temp[1]) - q)
        if end+1 == MAX:
            end = 0
        else:
            end += 1
        A[end] = temp
        cnt += q

Submission status: Accepted

Solution code:
N,q = map(int,input().split())
name = []
time = []
now = 0
for i in range(N):
    n,t = input().split()
    name.append(n)
    time.append(int(t))
while N != 0:
    if time[0] > q:
        t = time.pop(0)-q
        n = name.pop(0)
        time.append(t)
        name.append(n)
        now += q
    else:
        t = time.pop(0)
        n = name.pop(0)
        now += t
        print(n,now)
        N -= 1

Submission status: Accepted

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

tasks=[]

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

total_time=0

flag=1
while flag==1:
  flag=0
  del_index=[]
  for i in range(len(tasks)):
    if tasks[i][1]>q:
      tasks[i][1]-=q
      flag=1
      total_time+=q  
    else:
      total_time+=tasks[i][1]
      tasks[i][1]=0
      print(tasks[i][0], total_time)
      del_index.append(i)
  for i in reversed(del_index):
    del tasks[i]

Submission status: Accepted

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

total_time = 0
while len(que) != 0:
    p = que.pop(0)
    if p[1] - q <= 0:
        total_time += p[1]
        print(p[0], total_time)
    else:
        total_time += q
        p[1] -= q
        que.append(p)

Submission status: Accepted

Solution code:
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n,q = list(map(int, input().split()))
    elasped=0
    que=deque()
    for _ in range(n):
        pt=input().split()
        pt[1]=int(pt[1])
        que.append(pt)
    while que:
        p,t=que.popleft()
        elasped+=min(t,q)
        if t<=q:
            print(p,elasped)
        else:
            que.append([p,t-q])

main()

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-
# ALDS1_3_B: Queue

if __name__ == "__main__":
    # 数字入力　行数＋数字(1行1文字)
    N_Q = list(input().split())
    n, q = int(N_Q[0]), int(N_Q[1])
    time = 0
    FIN = []

    L = [input().split() for i in range(n)]
    temp_name = ""
    temp_time = 0

    while len(L) > 0:
        process_name = L[0][0]
        process_time = int(L[0][1])
        # print("process_name = {}, process_time = {}".format(process_name, process_time))

        if process_time <= q:
            time = time + process_time
            FIN.append([process_name, time])
            L.pop(0)
            # print("L = {}".format(L))
            # print("FIN = {}".format(FIN))
        else:
            time = time + q
            temp_name = L[0][0]
            temp_time = int(L[0][1]) - q
            L.pop(0)
            L.append([temp_name, temp_time])
            # print("L = {}".format(L))
    for i in range(len(FIN)):
        print("{} {}".format(FIN[i][0], FIN[i][1]))

Submission status: Accepted

Solution code:
from collections import deque

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

for _ in range(n):
    name, time = input().split()
    time = int(time)
    deq.append((time, name))
    
ans = []
cur = 0

while deq:
    time, name = deq.popleft()
    
    if time <= q:
        cur += time
        ans.append(f"{name} {cur}")
    else:
        cur += q
        deq.append((time - q, name))
        
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
from collections import deque

N, Q = [int(i) for i in input().split()]
q = deque()
for _ in range(N):
    p = input().split()
    q.append((p[0], int(p[1])))

current_time = 0
while len(q) > 0:
    p = q.popleft()
    if p[1] > Q:
        current_time += Q
        q.append((p[0], int(p[1])-Q))
    else:
        current_time += p[1]
        print(p[0], current_time)

Submission status: Accepted

Solution code:
n,q = map(int,input().split())
p = [0 for _ in range(n)]
time = 0
for i in range(n):
    a,m = input().split()
    p[i] = [a,int(m)]

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

Submission status: Accepted

Solution code:
#1-3 queue
from collections import deque
n,q=map(int,input().split())
queue = deque([])
for i in range(n):
    a,b=input().split()
    queue.append([a,int(b)])

clock=0
while len(queue)>0:
    now=queue.popleft()
    if now[1]>q:
        queue.append([now[0],now[1]-q])
        clock+=q
    else:
        print(now[0],clock+now[1])
        clock+=now[1]

Submission status: Accepted

Solution code:
def queue(nm,tm,q):
    total=0
    while nm:
        name=nm.pop(0)
        time=tm.pop(0)
        if q<time:
            time-=q
            total+=q
            nm.append(name)
            tm.append(time)

        else:
            total+=time
            print("{} {}".format(name, total))
    
    
def main():
    n,q=map(int,input().split())
    name=[]
    time=[]
    for i in range(n):
        nm,tm=input().split()
        name.append(nm)
        time.append(int(tm))

    queue( name, time, q)
    

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    args = input().split(' ')
    n = int(args[0])
    t = int(args[1])

    queue = []

    prolist = {}
    finish = []
    for i in range(n):
        datas = input().split(' ')
        prolist[datas[0]] = int(datas[1])
        # add to queue by order
        queue.append(datas[0])
    
    tottime = 0
    while len(queue) > 0:
        name = queue.pop(0)
        if prolist[name] == 0:
            pass
        else:
            if prolist[name] > t:
                # has some task unfinish
                prolist[name] -= t
                tottime += t
                queue.append(name)
            else:
                # finish all task, quit
                finish.append('%s %d' %(name, tottime + prolist[name]))
                tottime += prolist[name]
                prolist[name] = 0
    
    for info in finish:
        print(info)

Submission status: Accepted

Solution code:
from collections import deque


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


def main():
    n, q = map(int, input().split())
    queue = deque()
    for _ in range(n):
        name, time = input().split()
        queue.append(Process(name, time))

    time = 0
    while queue:
        process = queue.popleft()
        if process.time - q > 0:
            process.time -= q
            time += q
            queue.append(process)
        else:
            time += process.time
            print("{} {}".format(process.name, time))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
	n,q = map(int,input().split())
	que = []
	for _ in range(n):
		name, time = input().split()
		que += [[name, int(time)]]
	anst = 0
	while que != []:
		temp = que.pop(0)
		if temp[1] <= q:
			anst += temp[1]
			print(f"{temp[0]} {anst}")
		else:
			anst += q
			que += [[temp[0], temp[1]-q]]

main()

Submission status: Accepted

Solution code:
import heapq
N,Q = map(int,input().split())
nati = []
for i in range(N):
    na,ti = input().split()
    nati.append([str(na),int(ti)])

now = 0
while nati:
    na,ti = nati.pop(0)
    if ti > Q:
        ti-=Q
        nati.append([na,ti])
        now+=Q
    else:
        now+=ti
        print(na,now)

Submission status: Accepted

Solution code:
n,time = map(int,input().split())
p=[]
p.append(['p0','0'])
for i in range(n):
  p.append(input().split())
  
head = 1
tail = 0

def enque(x):
  global tail
  p[tail] = x;
  tail = (tail+1) % len(p)

def dequeue():
  global head
  x = p[head]
  head = (head+1) % len(p)
  return x;

checkTime = 0
while(head != tail):
  u = dequeue()
  c = min(time,int(u[1]))
  u[1] = int(u[1]) - c
  checkTime += c
  if int(u[1]) > 0:
    enque(u)
  else:
    print(u[0], checkTime)

Submission status: Accepted

Solution code:
import collections as col
A = []
A = col.deque(A)
n, q = map(int,input().split())
name = {}
time = []
for i in range(n):
    temp = input().split()
    name[temp[0]] = i
    time.append(int(temp[1]))

for x in name.keys():
    A.append(x)
t = 0

while len(A) > 0:
    if time[name[A[0]]] > q:
        time[name[A[0]]] -= q
        t += q
        A.append(A.popleft())
    else:
        t += time[name[A[0]]]
        print(A.popleft(),t)

Submission status: Accepted

Solution code:
n,q=list(map(int,input().split()))
ls=[]
for i in range(n):
    a,b = input().split()
    ls.append([a,int(b)])
done=[]
t=0
while ls!=[]:
    task=ls.pop(0)
    if task[1]<= q:
        t+=task[1]
        done.append([task[0],t])
    else:
        task[1] -= q
        t+=q
        ls+=[task]

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

Submission status: Accepted

Solution code:
class queue:
    def __init__(self):
        self.q = []
    def enqueue(self, x):
        self.q.append(x)
    def dequeue(self):
        ret = self.q[0]
        del self.q[0]
        return ret
    def size(self):
        return len(self.q)

que = queue()
n, q = map(int, input().split())
q = int(q)
for i in range(n):
    name, time = map(str, input().split())
    time = int(time)
    que.enqueue([name, time])
currentTime = 0
answerL = []
while que.size():
    cur = que.dequeue()
    if cur[1] <= q:
        currentTime += cur[1]
        answerL.append(cur[0]+' '+str(currentTime))
    else:
        currentTime+=q
        que.enqueue([cur[0], cur[1]-q])
for ans in answerL:
    print(ans)

Submission status: Accepted

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

moment = 0
while queue:
    name, time = queue.pop(0)
    remain = time - p
    if remain <= 0:
        moment += time
        print(name, moment)
    else:
        moment += p
        queue.append((name, remain))

Submission status: Accepted

Solution code:
# ALDS1_3_B
p_list = []
q_list = []
finished_list = []
time_list = []
time = 0

n, q = map(int, input().split())
for i in range(n):
    pi, qi = input().split()
    p_list.append(pi)
    q_list.append(int(qi))

##テスト用
# p_list = ["p1","p2","p3","p4","p5"]
# q_list = [150, 80, 200, 350, 20]

while len(p_list) > 0:
  processing_item = p_list.pop(0)
  processing_time = q_list.pop(0)
 
  if processing_time <= q:
    time += processing_time
    finished_list.append(processing_item)
    time_list.append(time)
  else:
    time += q
    processing_time -= q
    p_list.append(processing_item)
    q_list.append(processing_time)

for i in range(n):
#     print(finished_list, time_list)
  print(finished_list[i], time_list[i])

Submission status: Accepted

Solution code:

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

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

    def dequeue(self):
        if self.is_empty is True:
            return None
        else:
            return self.data.pop(0)

    def is_empty(self):
        if len(self.data) == 0:
            return True
        else:
            return False

    def is_full(self):
        pass


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

queue = Queue()
for i in range(n):
    name, time = input().split()
    time = int(time)
    queue.enqueue({'name': name, 'time': time})

time = 0
while queue.is_empty() is False:
    next_process = queue.dequeue()

    if next_process['time'] > q:
        time += q
        next_process['time'] -= q
        queue.enqueue(next_process)
    else:
        time += next_process['time']
        print(next_process['name'], time)

Submission status: Accepted

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

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

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

    def enqueue(self, x):
        if self.is_full():
            assert "オーバーフロー"
        self.queue[self.tail] = x
        if self.tail + 1 == self.n:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            assert "アンダーフロー"
        x = self.queue[self.head]
        if self.head + 1 == self.n:
            self.head = 0
        else:
            self.head += 1
        return x


n, q = map(int, input().split())
queue = Queue(n+1)
for _ in range(n):
    data = input().split()
    queue.enqueue((data[0], int(data[1])))
timer = 0
while True:
    process = queue.dequeue()
    if process[1] > q:
        queue.enqueue((process[0], process[1] - q))
        timer += q
    else:
        timer += process[1]
        print(process[0] + " " + str(timer))
    if queue.is_empty():
        break

Submission status: Accepted

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

wholetime = 0
while len(queue) != 0:
  target = queue.pop(0)
  time = int(target[1])
  if time <= q:
    wholetime += time
    print(target[0], wholetime)
  else:
#    print(target[0], 100)
    wholetime += q
    queue.append([target[0], time - q])

Submission status: Accepted

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

process = []
for _ in range(n):
    p, t = input().split()
    process.append([p, int(t)])
    
time_processed = 0
while process:
    p = process.pop(0)
    if p[1] > q: #仕事が終わらない
        p[1] = p[1] - q
        process.append(p)
        time_processed += q
    elif p[1] <= q: #仕事が終わる
        print(f"{p[0]} {time_processed + p[1]}")
        time_processed += p[1]

Submission status: Accepted

Solution code:
from copy import copy

n,q = map(int,input().split())
pro = [input().split()+[0,i] for i in range(n)]
#0:name 1:time 2:endtime 3:index
for i in range(n):
    pro[i][1] = int(pro[i][1])
queue = copy(pro)
head = 0
tail = n-1
time = 0
while head <= tail:
    task = queue[head]
    head += 1
    if task[1] <= q:
        time += task[1]
        pro[task[3]][2] = time
    else:
        time += q
        task[1] -= q
        queue.append(task)
        tail += 1

for i in sorted(pro,key=lambda x: x[2]):
    print(i[0],i[2])

Submission status: Accepted

Solution code:
from collections import deque

n,q=map(int,input().split())
que=deque([])
for _ in range(n):
    p,t=input().split()
    que.append((p,int(t)))
tm=0
while len(que):
    n1,n2=que.popleft()
    if n2>q:
        n2-=q
        que.append((n1,n2))
        tm+=q
    elif n2==q:
        print(n1,tm+q)
        tm+=q
    else:
        print(n1,tm+n2)
        tm+=n2

Submission status: Accepted

Solution code:
from queue import Queue


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


if __name__ == '__main__':
    n, q = map(int, input().split())
    arr = Queue()
    for _ in range(n):
        name, time = input().split()
        arr.put(Task(name, int(time)))
    all_time = 0
    while not arr.empty():
        task = arr.get()
        if task.time > q:
            arr.put(Task(task.name, task.time - q))
            all_time += q
        else:
            all_time += task.time
            print(task.name, all_time)

Submission status: Accepted

Solution code:
from collections import deque


m1 = input().split()
n = int(m1[0])
Q = int(m1[1])
q = deque()
number = deque()
time = 0
sum = 0
for i in range(n):
    m2 = input().split()
    a = int(m2[1])
    number.append(str(m2[0]))
    q.append(a)
    sum += a
j = 0
while time < sum:
    if q[j] < Q:
        time += q[j]
        print(number[j],time)
        if time == sum:
            break
        q.popleft()
        number.popleft()
    elif q[j] == Q:
        time += q[j]
        print(number[j],time)
        if time == sum:
            break
        q.popleft()
        number.popleft()
    else:
        number.append(number.popleft())
        q.append(q.popleft() - Q)
        time += Q
        if time == sum:
            break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import deque
import itertools

def roundrobin(iterables,ite2,act):
    aaa = deque(iterables)
    bbb = deque(ite2)

    endtime = 0
    while aaa:
        if(aaa[0] > act):        
            aaa[0] -= act
            endtime += act
            #yield next(aaa[0])
            
            aaa.rotate(-1)
            bbb.rotate(-1)
        else:
            endtime += aaa[0]
            print(bbb[0],endtime)
            aaa.popleft()
            bbb.popleft()


task,act = (int(x) for x in input().split())

queue = []
time = []
for i in range(task):
    q,t = input().split()
    queue.append(q)
    time.append(int(t))

roundrobin(time,queue,act)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

from collections import deque

n,q=map(int,input().split())
que = deque()
for _ in range(n):
    x,y = input().split()
    que.append([x,int(y)])
time=0
while len(que)!=0:
    x,y=que.popleft()
    if y<=q:
        time+=y
        print(x,time)
    else:
        y-=q
        que.append([x,y])
        time+=q

Submission status: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
a = deque()
for i in range(n):
    name, time = input().split()
    a.append([name, int(time)])
cnt = 0
while a:
    t = a.popleft()
    if t[1] <= q:
        cnt += t[1]
        print(t[0], cnt)
    else:
        cnt += q
        t[1] -= q
        a.append(t)

Submission status: Accepted

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

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

Submission status: Accepted

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

l = []
ltim = []
res = []
restim = []

for i in range(n):
    p,t = input().split()
    l.append(p)
    ltim.append(int(t))

ot = 0
qhead = 0
qtail = n

while qhead<qtail:
    cl = l[qhead]
    ct = ltim[qhead]
    if ct <= time:
        ot += ct
        res.append(cl)
        restim.append(ot)
        qhead += 1
    else:
        ot += time
        ct -= time
        l.append(cl)
        ltim.append(ct)
        qhead += 1
        qtail += 1


for o in range(n):
    print(res[o],restim[o])

Submission status: Accepted

Solution code:
n,time=input().split()


n=int(n)
time=int(time)

l=[]
ltim=[]
res=[]
restim=[]

for i in range(n):
    p,t=input().split()
    l.append(p)
    ltim.append(int(t))

ot=0
qhead=0
qtail=n

while qhead<qtail:
    cl=l[qhead]
    ct=ltim[qhead]
    if ct<=time:
        ot+=ct
        res.append(cl)
        restim.append(ot)
        qhead+=1
    else:
        ot+=time
        ct-=time
        l.append(cl)
        ltim.append(ct)
        qhead+=1
        qtail+=1


for o in range(n):
    print(res[o],restim[o])

Submission status: Accepted

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

name=[]
time=[]

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


i=0
timer=0

while(1):

    if time[i]<=q:

        timer+=time[i]
        x=name.pop(i)
        time.pop(i)
        remains-=1
        print(x,timer)
        if remains==0: break
        i=i%remains
    else:
        time[i]-=q
        timer+=q
        i=(i+1)%remains

Submission status: Accepted

Solution code:
from collections import deque

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

Q = deque()

class Info:
    def __init__(self,arg_name,arg_rest_time):
        self.name = arg_name
        self.rest_time = arg_rest_time

for i in range(n):
    tmp = input().split()
    Q.append(Info(tmp[0],int(tmp[1])))

current_time = 0

while len(Q)>0:
    info = Q.popleft()
    if info.rest_time > LIMIT:
        info.rest_time -= LIMIT
        current_time += LIMIT
        Q.append(info)
    else:
        current_time += info.rest_time
        print("%s %d"%(info.name,current_time))

Submission status: Accepted

Solution code:
n,time=input().split()


n=int(n)
time=int(time)

l=[]
ltim=[]
res=[]
restim=[]

for i in range(n):
    p,t=input().split()
    l.append(p)
    ltim.append(int(t))

ot=0
qhead=0
qtail=n

while qhead<qtail:
    cl=l[qhead]
    ct=ltim[qhead]
    if ct<=time:
        ot+=ct
        res.append(cl)
        restim.append(ot)
        qhead+=1
    else:
        ot+=time
        ct-=time
        l.append(cl)
        ltim.append(ct)
        qhead+=1
        qtail+=1


for o in range(n):
    print(res[o],restim[o])

Submission status: Accepted

Solution code:
from collections import deque

num, quan = map(int,input().split())


name = deque([])
time = deque([])
for i in range(num):
    n,t = map(str,input().split())
    name.append(n)
    time.append(int(t))

counttime = 0

while len(time) != 0:
    a = name.popleft()
    name.append(a)
    
    b = time.popleft()
    b = b - quan
    
    if b > 0:
        time.append(b)
        counttime += quan
    else:
        c = b + quan
        counttime += c
        print(name[-1]+" "+str(counttime))
        name.pop()

Submission status: Accepted

Solution code:
from collections import deque

process,quantum=map(int,input().split())

que=deque()

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

time=0
    
while que:
    name_t=que.popleft()
    if name_t[1]<=quantum:
        time+=name_t[1]
        print(name_t[0],time)
    else:
        time+=quantum
        name_t[1]-=quantum
        que.append(name_t)

Submission status: Accepted

Solution code:
N , Q = [int(i) for i in input().split()]

name = []
time = []

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

count = 0
name2 = []
time2 = []

while len(name)>0:
    st = name.pop(0)
    p = int(time.pop(0))
    
    if p > Q:
        name.append(st)
        time.append(p-Q)
        count += Q
    else:
        count += p
        name2.append(st)
        time2.append(count)

for i in range(N):
    print(name2[i], time2[i])

Submission status: Accepted

Solution code:
#17D8101028I tou koutetsu  2019/10/10
#ID:tanghaozhe 
#python
from collections import deque
n,q= map(int,input().split(" "))
data=deque([])
for i in range(n):
    name,time=input().split()
    time=int(time)
    cur = [name,time]
    data.append(cur)
    
t=0
while len(data)>0:
    cur=data.popleft()
    spend=min(cur[1],q)
    cur[1]-=spend
    t+=spend
    if(cur[1]==0):
        print(cur[0],t)
    else:
        data.append(cur)


#150 80 200 350 20

Submission status: Accepted

Solution code:
import collections

def func(n, q, task):
    L = collections.deque()
    for i in reversed(task): L.appendleft(i)
    exetime = 0
    while L:
        x = L.popleft()
        if int(x[1]) > q:
            exetime += q
            x[1] = int(x[1]) - q
            L.append(x)
        else:
            exetime += int(x[1])
            print (x[0] + " " + str(exetime))

n, q = map(int, input().split(" "))
task = [input().split(" ") for _ in range(n)]
func(n, q, task)

Submission status: Accepted

Solution code:
qname=[]
qt=[]
cnt=0
name=[]
t=[]
n,q=list(map(int,input().split()))
for i in range(n):
    a=input().split()
    name.append(a[0])
    t.append(int(a[1]))
while(len(t)!=0):
    tmp=t.pop(0)-q
    cnt+=q
    if tmp==0:
        qname.append(name.pop(0))
        qt.append(cnt)
    elif tmp<0:
        qname.append(name.pop(0))
        cnt+=tmp
        qt.append(cnt)
    else:
        t.append(tmp)
        name.append(name.pop(0))
for i in range(n):
    print(qname[i],qt[i])

Submission status: Accepted

Solution code:
def main():
    n, q = (int(i) for i in input().split())
    nt = [[i for i in input().split()] for j in range(n)]
    from collections import deque
    nt = deque(nt)
    time = 0
    finished = []
    while nt:
        time += min(int(nt[0][1]),q)
        nt[0][1]= max(0, int(nt[0][1]) - q)
        if int(nt[0][1]) == 0:
            finished.append((nt[0][0],time))
            nt.popleft()
        else:
            nt.rotate(-1)
    
    for f in finished:
        print(*f)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = 0
while len(time) != 0:
    x = name.pop(0)
    y = int(time.pop(0))
    for i in range(q):
        y -= 1
        cnt += 1
        if y <= 0:
            print(x, cnt)
            break
    if y <= 0:
        pass        
    else:
        name.append(x)
        time.append(y)

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
task = []
for _ in range(n):
    s = input().split()
    task.append([s[0], int(s[1])])
    
ans = 0
while len(task):
    t = task.pop(0)
    if t[1] - q <= 0:
        ans += t[1]
        print(t[0], ans)
    else:
        ans += q
        task.append([t[0], t[1]-q])

Submission status: Accepted

Solution code:
from collections import deque

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

    procs = [input().split() for x in range(n)]
    procs = deque([[proc[0], int(proc[1])] for proc in procs])

    finished_procs = []
    t = 0
    
    while len(procs) > 0:
        proc = procs.popleft()

        t += min(q, proc[1])

        if q - proc[1] >= 0:
            finished_procs.append([proc[0], t])
        else:
            proc[1] -= q
            procs.append(proc)

    for proc in finished_procs:
        print(proc[0] + ' ' + str(proc[1]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

_target_list = []
for i in range(process_count):
    _input = input().split()
    _target_list.append([_input[0], int(_input[1])])
target_list = deque(_target_list)

def calc_process_time(target_list, process_limit):
    process_end_list = []
    process_time = 0
    while target_list:
        target_value = target_list.popleft()
        if target_value[1] > process_limit:
            target_value[1] -= process_limit
            target_list.append(target_value)
            process_time += process_limit
        else:
            process_time += target_value[1]
            process_end_list.append([target_value[0], process_time])
    return process_end_list

process_end_list = calc_process_time(target_list, process_limit)
for value in process_end_list:
    print(value[0], value[1])

Submission status: Accepted

Solution code:
from typing import TypeVar, Generic, List, Deque

T = TypeVar('T')

class Queue(Generic[T]):
	def __init__(self) -> None:
		self._container: Deque[T] = Deque()

	@property
	def empty(self) -> bool:
		return not self._container # コンテナが空ならば真となる

	def push(self, item: T):
		self._container.append(item)

	def pop(self) -> T:
		return self._container.popleft() # FIFO

	def __repr__(self) -> str:
		return repr(self._container)


if __name__ == "__main__":
	a = list(map(int, input().split()))
	n = a[0]
	q = a[1]
	queue = Queue()
	for _ in range(n):
		b = list(input().split())
		queue.push([b[0], int(b[1])])
	time = 0
	while not queue.empty:
		item = queue.pop()
		if item[1] - q <= 0:
			time += item[1]
			print(f"{item[0]} {time}")
		else:
			item[1] -= q
			queue.push(item)
			time += q

Submission status: Accepted

Solution code:
from collections import deque

class Data:
    def __init__(self, name, value):
        self.name = name
        self.value = value

Q = deque()

n, q = map(int, input().split())
for _ in range(n):
    name, value = input().split()
    tmp = Data(name, int(value))
    Q.append(tmp)

current_time = 0
done = 0

while True:
    datum = Q.popleft()
    if datum.value > q:
        current_time += q
        datum.value -= q
        Q.append(datum)
        
    else:
        current_time += datum.value
        print("%s %d"%(datum.name, current_time))
        done += 1
    if done == n:
        break