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([input().split() for _ in range(n)])
a = []
tt = 0

while d:
    t = int(d[0][1])
    if t > q:
        tt += q
        d.append([d[0][0], str(t-q)])
        d.popleft()
    else:
        tt += t
        p = d.popleft()
        a.append([p[0], tt])

for n, t in a:
    print(n, t)

Submission status: Accepted

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

    def enqueue(self, x):
        if not self.isfull():
            self.array[self.tail] = x
            self.tail += 1
            self.tail = self.tail % self.n
        else:
            raise ValueError

    def dequeue(self):
        if not self.isempty():
            val = self.array[self.head]
            self.head += 1
            self.head = self.head % self.n
            return val
        else:
            return False

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

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


def main():
    n, q = map(int, input().split())
    queue = Queue(n)
    time = 0

    for _ in range(n):
        query = input().split()
        queue.enqueue(query)

    task = True
    while not queue.isempty():
        task = queue.dequeue()
        if int(task[1]) > q:
            time += q
            tmp_time = int(task[1]) - q
            task = [task[0], tmp_time]
            queue.enqueue(task)
        else:
            time += int(task[1])
            print(task[0], time)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, q = map(int,input().split())
Q = [0]*(n+1)
head = 0
tail = 0

def enqueue(x):
    global tail
    global Q

    Q[tail] = x
    tail += 1
    if tail == n+1:
        tail = 0

def dequeue():
    global Q
    global head

    X = Q[head]

    head += 1
    if head == n+1:
        head = 0

    return X

def main():
    global n
    global q
    global Q
    global tail
    global head

    time = 0
    cnt = 0

    que = [list(input().split()) for _ in range(n)]
    for i in range(n):
        enqueue(que[i])

    while True:
        temp = dequeue()
        if int(temp[1]) <= q:
            time += int(temp[1])
            print(temp[0] + ' ' + str(time))
            cnt += 1
        else:
            time += q
            temp[1] = str( int(temp[1]) - q )
            enqueue( temp )

        if cnt == n:
            break

main()

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def main():
    n, q = map(int, input().split())
    nt = [None] * n
    for i in range(n):
        line = input().split()
        nt[i] = [line[0], int(line[1])]

    queue = deque(nt)
    time = 0
    ans = []
    while queue:
        p = queue.popleft()
        if p[1] <= q:
            time += p[1]
            ans.append((p[0], time))
        else:
            p[1] -= q
            time += q
            queue.append(p)

    for a in ans:
        print(*a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

def round_robin_scheduling(p,t):
    q=deque()
    for i in p:#listをqueueに持ち直す
        q.append(i)
    result=[]
    past_time=0
    while q:
        now=q.popleft()
        name,time=now
        rest_time=time-t
        if rest_time>0:#クオンタムtより必要時間が多いなら最後尾に追加
            q.append((name,rest_time))
            past_time+=t
        else:#処理終了
            past_time+=time
            result.append((name,past_time))
    return result
n,t=map(int,input().split())
process=[]
for i in range(n):
    name,time=input().split()
    time=int(time)
    process.append((name,time))

for name,time in round_robin_scheduling(process,t):
    print(name+" "+str(time))

Submission status: Accepted

Solution code:
import time
import sys
import io
import re
import math
from Queue import Queue
import collections

start = time.clock();
i = 0
(n, q) = map(int, raw_input().split())

datalist = [raw_input().split() for _ in range(n)]
datalist = collections.deque(datalist)

#print(datalist)
while len(datalist):
    data = datalist.popleft()
    
    data[1] = int(data[1])
    
    if data[1] <= q:
        i += data[1]
        print data[0], i
    else:
        i += q
        data[1] -= q
        datalist.append(data)

Submission status: Accepted

Solution code:
from collections import deque

n,q=map(int,input().split())
Queue=deque()
for _ in range(n):
  Queue.append(input())
#print(Queue)
ans=0
while len(Queue)>0:
  x=Queue.popleft()
  #print('---')
  #print(x)
  name,time=x.split()
  t=int(time)
  if t>q:
    ans+=q
    Queue.append(name+' '+str(t-q))
  else:
    ans+=t
    print(name,ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

class Queue:
    def __init__(self, process_list,quontime):
        self.process_list = process_list
        self.quontime = quontime
        self.elapsed_time = 0

    def process_done(self, process):
        process.update_leavetime_mili_seconds(process.leavetime_mili_seconds)
        print("{} {}".format(process.name,self.elapsed_time))

    def execute(self):
        while len(self.process_list) > 0:
            target_process = self.process_list.pop(0)
            if target_process.leavetime_mili_seconds <= self.quontime:
                self.elapsed_time += target_process.leavetime_mili_seconds
                self.process_done(target_process)
            else:
                self.elapsed_time += self.quontime
                target_process.update_leavetime_mili_seconds(self.quontime)
                self.process_list.append(target_process)

class Process:
    def __init__(self, arg_name,leavetime_mili_seconds):
        self.name = arg_name
        self.leavetime_mili_seconds = leavetime_mili_seconds
        # self.is_done = False

    def update_leavetime_mili_seconds(self, shori_time):
        self.leavetime_mili_seconds -= shori_time


n, q = map(int,stdin.readline().rstrip().split())
process_list = []
for i in range(n):
    input_t = stdin.readline().rstrip().split()
    process_list.append(Process(input_t[0], int(input_t[1])))
queue = Queue(process_list, q)
queue.execute()

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
queue = []
for i in range(n):
  name, time = map(str, input().split())
  queue.append([name, int(time)])
    
length = 0
while queue:
  num = queue[0]
  if num[1] <= q:
    length += num[1]
    queue.pop(0)
    print(num[0], length)
  else:
    length += q
    queue.pop(0)
    queue.append([num[0], int(num[1]-q)])

Submission status: Accepted

Solution code:
N,Q = map(int, input().split())
import collections
dqn = collections.deque()
dqt = collections.deque()

def f(s):
    lst = s.split()
    return lst[0], int(lst[1])

for _ in range(N):
    ele = f(input())
    dqn.append(ele[0])
    dqt.append(ele[1])

Time = 0
while len(dqt) > 0:
    dqtime = dqt.popleft()
    dqname = dqn.popleft()
    if dqtime > Q:
        Time += Q
        dqt.append(dqtime - Q)
        dqn.append(dqname)
    else:
        Time += dqtime
        print(dqname,Time)

Submission status: Accepted

Solution code:
def resolve():
    from collections import deque
    n, q = [int(i) for i in input().split()]
    P = [input().split() for _ in range(n)]
    que = deque(P)
    totalTime = 0
    while len(que) > 0:
        name, time = que.popleft()
        time = int(time)
        if time <= q:
            totalTime += time
            print(name, totalTime)
        else:
            totalTime += q
            que.append([name, str(time - q)])


resolve()

Submission status: Accepted

Solution code:
from collections import deque

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

for i in range(n):
    pro[i][1] = int(pro[i][1])

que = deque(pro)
done = False
time = 0

order = []

while not done:
    if len(que) == 0:
        done = True
        break
    now = que.popleft()
    t = now[1]
    name = now[0]
    if 0 < t <= q:
        time += t
        order.append(name + ' ' + str(time))
    if t > q:
        time += q
        t -= q
        que.append([name] + [t])

for i in order:
    print(i)

Submission status: Accepted

Solution code:
import collections
import queue
Q = collections.deque()
ans = 0
base = 0
#print(ans)
line = input()
#print(line)
a = line.split()
#print(a)
n,q = map(int,a)

def work(listed):
    global ans
    global base
    v = int(listed[1])
    if v <= q:
        ans += v
        print(listed[0],ans)
        base += 1
    else:
        #print(q)
        #print(ans)
        ans += q
        v -= q
        listed[1] = str(v)
        Q.append(listed)

for i in range (n):
    listed = list(input().strip().split())
    #print(ans)
    work(listed)

#for i in Q:
while base < n:
    listed = Q.popleft()
    work(listed)
    #print(Q)

Submission status: Accepted

Solution code:
import collections

n,q= map(int,input().split())
time= collections.deque()
name= collections.deque()
for _ in range(n):
    x,y= input().split()
    name.append(x)
    time.append(int(y))

cur=0
while True:
    if len(time)==0:
        break
    temp= time.popleft()
    if temp<= q:
        cur= temp+cur
        print(name.popleft(),cur)
        
    else:
        name.append(name.popleft())
        time.append(temp-q)
        cur+=q

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
ans = []
time = 0
while a:
    j = a.pop(0)
    if int(j[1]) > q:
        j[1] = str(int(j[1]) - q)
        a.append(j)
        time += q
    else:
        time += int(j[1])
        ans.append([j[0], str(time)])
for i in range(n):
    print(' '.join(ans[i]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    N,Q = map(int,input().split()) 
    q = deque([])
    for _ in range(N):
        name,time = input().split()
        q.append((name,int(time)))
    
    ans = []
    t = 0
    while q:
        name,time = q.popleft()
        if time <= Q:
            t += time
            ans.append((name,t))
        else:
            t += Q
            time -= Q
            q.append((name,time))
    print('\n'.join(' '.join(map(str,a)) for a in ans))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

def main():
    n, p = map(int, input().split())
    q = deque([])
    score = 0
    cnt = 0
    for i in range(n):
        nt = list(map(str, input().split()))
        nt[1] = int(nt[1])
        q.append(nt)
    while q:
        tmp = q.popleft()
        if tmp[1] > p:
            score += p
            tmp[1] -= p
            cnt += 1
            q.append(tmp)       
        else:
            score += tmp[1]
            cnt += 1
            print(tmp[0], score)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
n,q = map(int,input().split())
ans = 0
NT = [list(input().split()) for i in range(n)]

queue = deque(NT)

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

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
queue = deque()
for _ in range(n):
    n, t = input().split()
    queue.append([n, int(t)])
time = 0
finish = []
while len(queue) > 0:
    l = queue.popleft()
    cost = min(q, l[1])
    l[1] -= cost
    time += cost
    if l[1] == 0:
        finish.append((l[0], time))
    else:
        queue.append(l)
for f in finish:
    print(*f)

Submission status: Accepted

Solution code:
from collections import deque

queue = deque()
total_time = 0
n, q = map(int,input().split(' '))
for _ in range(n):
    name, time = input().split(' ')
    queue.append((name,int(time)))


while True:
    try:
        name, time = queue.popleft()
        if time - q <= 0:
            total_time += time
            print(name,total_time,sep=' ')
        elif time - q > 0:
            total_time += q
            queue.append((name,time-q))
    except IndexError:
        break

Submission status: Accepted

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

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


class Queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.q = [0] * 10 ** 6
        self.max = 10 ** 6

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

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

    def enqueue(self, x):
        if self.isfull():
            return "Full"
        else:
            self.q[self.tail] = x
            self.tail += 1

        if self.tail == self.max:
            self.tail = 0

    def dequeue(self):
        if self.isempty():
            return "Empty"
        else:
            self.x = self.q[self.head]
            self.head += 1

        if self.head == self.max:
            self.head = 0

        return self.x


queue = Queue()

for p in prosess:
    queue.enqueue([p[0], int(p[1])])

now_time = 0

while not queue.isempty():
    name, time = queue.dequeue()

    if time <= q:
        now_time += time
        print(name, now_time)
    else:
        time -= q
        now_time += q
        queue.enqueue([name, time])

Submission status: Accepted

Solution code:
def scheduling(A,n,q):
    ans = []
    time = 0
    while A != []:
        x = A.pop(0)
        if q < x[1]:
            x[1] -= q
            time += q
            A.append(x)
        elif x[1] <= q:
            time += x[1]
            x[1] = time
            ans.append(x)

    return ans



if __name__ == '__main__':
    n,q = [int(i) for i in input().split()]
    A = []
    for i in range(n):
        a = input().split()
        a[1] = int(a[1])
        A.append(a)
    ans = scheduling(A,n,q)
    for i in range(n):
        print(ans[i][0],ans[i][1])

Submission status: Accepted

Solution code:
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
n,q = map(int, input().split())
A = deque()
for _ in range(n):
    a,b = input().split()
    A.append([a,int(b)])

t = 0
while True:
    a,b = A.popleft()
    if b > q:
        b = b - q
        t += q
        A.append([a,b])
    else:
        t += b
        print(f'{a} {t}')
    if len(A)==0:
        break

Submission status: Accepted

Solution code:
class queue():

    data = []
    cnt = 0

    def __init__(self):
        self.cnt = 0

    def add(self, a):
        self.data.append(a)

    def get(self):
        target = self.data[self.cnt]
        self.cnt += 1
        return target


buf = queue()

n, q = map(int, input().split())
for _ in range(n):
    name, time = input().split()
    time = int(time)

    buf.add([name, time])

finished = []
now = 0
while True:
    name, time = buf.get()
    if time - q > 0:
        buf.add([name, time-q])
        now += q
    else:
        finished.append([name, now+time])
        now += time

    if len(buf.data) == buf.cnt:
        break

for i in finished:
    print(i[0], i[1])

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
from collections import deque
import math



def resolve():
    n, q = map(int, input().split())
    que = deque([])
    for i in range(n):
        name, time = input().split()
        name = str(name)
        time = int(time)
        que.append({'name': name, 'time': time})
    
    cur_time = 0
    while que:
        cur = que.popleft()
        if cur['time'] > q:
            cur['time'] -= q
            cur_time += q
            que.append(cur)
        else:
            cur_time += cur['time']
            print("{} {}".format(cur['name'], cur_time))

resolve()

Submission status: Accepted

Solution code:
n,q = map(int,input().split())
total = 0
que_list=[]
finish_list=[]


for i in range(n):
    que_list.append(input().split())


while que_list:
    m = que_list.pop(0)
    if int(m[1]) > q:
        total += q
        m[1] = int(m[1]) - q
        que_list.append(m)
    else:
        total+=int(m[1])
        m[1] = total
        finish_list.append(m)
        
for i in range(len(finish_list)):
    print(finish_list[i][0],finish_list[i][1])

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
que, result = [], []
t = 0

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

while len(que) != 0:
    a = que[0][1] - q
    if a > 0:
        t = t + q
        que.append([que[0][0], a])
        del(que[0])
    elif a == 0:
        t = t + q
        result.append([que[0][0], t])
        del(que[0])
    else:
        t = t + que[0][1]
        result.append([que[0][0], t])
        del(que[0])

for r in result:
    print("{} {}".format(r[0], r[1]))

Submission status: Accepted

Solution code:
# ALDS1_3_B.py
from collections import deque as queue
N, Q = map(int, input().split())
q = queue()
for i in range(N):
    n, t = input().split()
    q.append((n, int(t)))
total = 0
while len(q) != 0:
    n, t = q.popleft()
    if t <= Q:
        total += t
        print(n, total)
    else:
        total += Q
        q.append((n, t-Q))

Submission status: Accepted

Solution code:
from collections import deque


def main():
    n, q = map(int, input().split())
    processes = deque()
    elapsed_time = 0

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

    while True:
        if len(processes) == 0:
            break

        process = processes.popleft()
        if process[1] <= q:
            elapsed_time += process[1]
            print(process[0], elapsed_time)
        else:
            elapsed_time += q
            process[1] -= q
            processes.append(process)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

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

queue = deque()
for i in range(n):
    N, T = input().split()
    queue.append([N, int(T)])

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

Submission status: Accepted

Solution code:
from collections import deque

totaltime = 0

n, q = (int(x) for x in input().split())


Q = deque()

for i in range(n):
    name, time = (x for x in input().split())
    Q.append([name,int(time)])
    
while len(Q) != 0:
    process = Q.popleft()
    time = process[1] - q
    if time > 0:
        process[1] = time
        totaltime += q
        Q.append(process)
        
    else:
        totaltime += process[1]
        print(process[0] + ' ' + str(totaltime))

Submission status: Accepted

Solution code:
class Proc:
    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 = list(input().split())
    time = int(time)
    p = Proc(name, time)
    queue.append(p)

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

Submission status: Accepted

Solution code:
from collections import deque
from sys import stdin
input = stdin.readline

n,q = map(int, input().split())
olist = deque()
for i in range(n):
    p,t = map(str, input().split())
    olist.append([p, int(t)])
count = 0
while olist:
    order = olist.popleft()
    remaintime = order[1] - q
    if remaintime > 0:
        count += q
        olist.append([order[0], remaintime])
    else:
        count += order[1]
        print(order[0], count)

Submission status: Accepted

Solution code:
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, q = LI()
    nt = collections.deque()

    for _ in range(n):
        name, time = LSS()
        nt.append([name, int(time)])

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
class queue:
    def __init__(self):
        self.V = []
        self.T = []
    def isEmpty(self):
        return len(self.V) == 0
    def enqueue(self,lis):
        self.T.append(lis[0])
        self.V.append(int(lis[1]))
    def dequeue(self):
        title = self.T[0]
        value = self.V[0]
        self.T = self.T[1:len(self.T)]
        self.V = self.V[1:len(self.V)]
        return [title,value]
n,q = list(map(int,input().split()))
time = 0
Q = queue()
totalT = 0
for i in range(n):
    arg = input().split()
    totalT += int(arg[1])
    if int(arg[1]) <= q:
        time += int(arg[1])
        print(f"{arg[0]} {time}")
    else:
        time += q
        Q.enqueue([arg[0],int(arg[1])-q])
    
while time<totalT:
    l = Q.dequeue()
    if l[1]<=q:
        time += l[1]
        print(f"{l[0]} {time}")
    else:
        time += q
        Q.enqueue([l[0],int(l[1])-q])

Submission status: Accepted

Solution code:
from collections import deque

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

for _ in range(n):
    p = [x for x in input().split()]
    Q.append(p)

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

Submission status: Accepted

Solution code:
from collections import deque

a,b = map(int, input().split())
d = deque()
s = deque()
for i in range(a):
    c,g = map(str,input().split())
    d.append(int(g))
    s.append(c)

ans_s = []
ans_num = []
count = 0
while True:
    count += b
    if len(d) == 0:
        break
    e = d.popleft()
    f = s.popleft()
    if e - b <= 0:
        ans_s.append(f)
        count += (e-b)
        ans_num.append(count)
    else:
        d.append(e - b)
        s.append(f)
for i in range(a):
    print(str(ans_s[i]) + ' ' + str(ans_num[i]))

Submission status: Accepted

Solution code:
from collections import deque
n,q = map(int,input().split())
deq = deque([])
for i in range(n):
    A = input().split()
    s = A[0]
    m = int(A[1])
    deq.append([s,m])
ans = 0
while deq:
    p = deq.popleft()
    if 0 < p[1] <= q:
        ans += p[1]
        print(p[0],ans)
    else:
        ans += q
        p[1] -= q
        deq.append([p[0],p[1]])

Submission status: Accepted

Solution code:
import collections
n,q = map(int,input().split())
item = []
for i in range(n):
    p,val = input().split()
    item.append([p,int(val)])
Queue = collections.deque([])
for i in range(n):
    Queue.append([item[i][0],item[i][1]])
time = 0
while Queue:
    name,val = Queue.popleft()
    if val>q:
        val -= q
        Queue.append([name,val])
        time += q
    else:
        time += val
        print(name,time)

Submission status: Accepted

Solution code:
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0

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

while len(queue) > 0:
    name, time = queue.pop(0)
    if time > quantum:
        sumOfTime += quantum
        queue.append([name, time - quantum])
    else:
        sumOfTime += time
        print(name, sumOfTime)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def round_robin(queue_list, t):
    elapsed_time = 0
    while len(queue_list) > 0:
        p, c = queue_list.pop(0)
        if c-t > 0:
            elapsed_time += t
            queue_list.append([p, c-t])
        else:
            elapsed_time += c
            print("{} {}".format(p,elapsed_time))

N, cpu_time = map(int,input().split())
queue_list = []
for i in range(N):
    process,cost = input().split()
    queue_list.append([process, int(cost)])

round_robin(queue_list, cpu_time)

Submission status: Accepted

Solution code:
from collections import deque

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

for i 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('%s %d' % (name, cur))
    else:
        cur += q
        deq.append((time - q, name))

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
class queue:
    val = []
    def __init__(self,arr):
        self.val = arr

    def push_queue(self,el):
        self.val.append(el)

    def pop_queue(self):
        return self.val.pop(0)



n,q = map(int,input().split())
process = [input().split() for a in range(n)]
for a in process:
    a[1] = int(a[1])

queued_process = queue(process)

time_count = 0
while True:
    if queued_process.val[0][1] > q:
        time_count += q
        queued_process.val[0][1] -= q
        queued_process.push_queue(queued_process.pop_queue())
    else:
        time_count += queued_process.val[0][1]
        queued_process.val[0][1] = 0
        print(f'{queued_process.val[0][0]} {time_count}')
        queued_process.pop_queue()
    if queued_process.val == []:
        break

Submission status: Accepted

Solution code:
import math
import sys
import itertools
# import numpy as np

def main():
  n,q = map(int, input().split())
  process = [input().split() for _ in range(n)]
  

  total_time = 0

  while len(process) > 0:
    time = int(process[0][1])

    if time <= q:
      total_time += time
      print(process[0][0], total_time)
    else:
      total_time += q
      process.append([process[0][0], str(time - q)])

    process.pop(0)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
nq = list(map(int, input().split()))
queue = list()

for i in range(nq[0]):
    queue.append(input().split())

ti = 0
cur = 0
while int(queue[cur][1]) > 0:
    num = queue[cur]
    syori = int(num[1]) - nq[1]
    
    if syori > 0:
        num[1] = syori
        queue.append(num)
        ti += nq[1]
    else:
        ti += int(num[1])
        print('{} {}'.format(num[0], ti))
    cur += 1
    
    if len(queue) <= cur:
        break

Submission status: Accepted

Solution code:
num,MAX = map(int,input().split())
queue = []
total_time = 0
[queue.append(input().split()) for _ in range(num)]
flag = 1
while flag:
  if len(queue) == 0:
    break
  queue[0][1] = int(queue[0][1])
  total_time += min(MAX,queue[0][1])
  queue[0][1] -= min(MAX,queue[0][1])
  temp = queue[0]
  queue.pop(0)
  if temp[1] == 0:
    print(f"{temp[0]} {total_time}")
    continue
  queue.append(temp)

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    n, q = list(map(int, input().split()))
    queue = deque()
    t = 0

    for _ in range(n):
        name, time = input().split()
        queue.append((name, int(time)))

    while len(queue):
        name, time = queue.popleft()

        if time <= q:
            t += time
            print(name, t)
        else:
            t += q
            time -= q
            queue.append((name, time))

Submission status: Accepted

Solution code:
n,v=map(int,input().split())
p_array=[]
total_num=0
i_cnt=0
for i in range(n):
    p_array.append(list(input().split()))
    p_array[i][1]=int(p_array[i][1])
while len(p_array) != 0:
    for i in range(n):
        if v < p_array[i-i_cnt][1]:
            p_array[i-i_cnt][1] -= v
            total_num += v
        else:
            total_num+=p_array[i-i_cnt][1]
            print(p_array[i-i_cnt][0],total_num)
            p_array.pop(i-i_cnt)
            i_cnt += 1
            n -= 1
    i_cnt=0

Submission status: Accepted

Solution code:
class queClass:

	def __init__(self, qtime, valuelist):
		self.qtime = qtime
		self.valuelist = valuelist
		self.stime = 0

	def run(self):
		time = self.qtime
		if time < self.valuelist[0][1]:  # クオンタム内に処理できなかった場合
			self.valuelist.append([self.valuelist[0][0], self.valuelist[0][1] - time])
			self.valuelist.remove(self.valuelist[0])
			self.stime = self.stime + self.qtime
		else:  # クオンタム内に処理できた場合
			self.stime = self.stime + self.valuelist[0][1]
			print('{0} {1}'.format(self.valuelist[0][0], self.stime))
			self.valuelist.remove(self.valuelist[0])
			if len(self.valuelist) == 0:
				exit(0)
		return


n, q = map(int, input().split())
inplist = []
for i in range(0, n):
	a, b = input().split()
	inplist.append([a, int(b)])
# print(inplist)
que = queClass(q, inplist)
while True:
	que.run()

Submission status: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
deq = deque()
for i 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("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time-q, name))
print(*ans, sep="\n")