Problem:
There are n processes in a queue. Each process has name i and time i .  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  name 1 time 1  name 2 time 2 ...  name n time n  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. name i and time i 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 ≤ time i ≤ 50000  1 ≤ length of name i ≤ 10  1 ≤ Sum of time i ≤ 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

Solution (Python):
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():
    
    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)

    
    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()

Solution (Python):



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.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()
"""

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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

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
	


for item in result:
	print(item)

Solution (Python):
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

Solution (Python):
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

Solution (Python):
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]

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):




if __name__ == "__main__":
    
    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])
        

        if process_time <= q:
            time = time + process_time
            FIN.append([process_name, time])
            L.pop(0)
            
            
        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])
            
    for i in range(len(FIN)):
        print("{} {}".format(FIN[i][0], FIN[i][1]))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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]

Solution (Python):
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()

Solution (Python):
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])
        
        queue.append(datas[0])
    
    tottime = 0
    while len(queue) > 0:
        name = queue.pop(0)
        if prolist[name] == 0:
            pass
        else:
            if prolist[name] > t:
                
                prolist[name] -= t
                tottime += t
                queue.append(name)
            else:
                
                finish.append('%s %d' %(name, tottime + prolist[name]))
                tottime += prolist[name]
                prolist[name] = 0
    
    for info in finish:
        print(info)

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):

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))





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[i], time_list[i])

Solution (Python):

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)

Solution (Python):
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

Solution (Python):
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:

    wholetime += q
    queue.append([target[0], time - q])

Solution (Python):
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]

Solution (Python):
from copy import copy

n,q = map(int,input().split())
pro = [input().split()+[0,i] for i in range(n)]

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])

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):

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
            
            
            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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
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])

Solution (Python):
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

Solution (Python):
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))

Solution (Python):
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])

Solution (Python):
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()

Solution (Python):
import heapq
import queue
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


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


N,LIMIT = map(int,input().split())
Q = deque()


for _ 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))

Solution (Python):
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)

Solution (Python):
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])

Solution (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)

Solution (Python):
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)

Solution (Python):
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])

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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])