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())
listA = []
t=1
while t <=n:  # 変な書き方をしていると思います、、、
    try:
        listA.append(input().split())
        t +=1
    except:
        break

result=[]
qu = deque()
for i in range(n):
    qu.append(listA[i]) # プロセスを順番にキューに入れる

time = 0    # 処理を開始してからの経過時間を入れる
while True:
    try:
        task = qu.popleft()     # 今処理するプロセスを取り出す
        if int(task[1]) <= q:   # クオンタム内で処理が完了するかを判断
            time += int(task[1]) # 処理時間を加える
            result.append([task[0], time]) 
        else:
            time += q # クオンタム目一杯処理を行ったのでクオンタム分を加える
            task[1] = int(task[1]) - q # 残りの処理時間
            qu.append(task) # 待ち行列の最後尾に追加
    except:
        break

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

Submission status: Accepted

Solution code:
N, Q = map(int, input().split())
from collections import deque
queue = deque([])

time = 0
for _ in range(N):
    name, t = input().split()
    t = int(t)
    queue.append([name, t])

while queue:
    process = queue.popleft()
    red = min(Q, process[1])
    time += red
    process[1] -= red
    if process[1] == 0:
        print(process[0], time)
    else:
        queue.append(process)

Submission status: Accepted

Solution code:
from collections import deque

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

t = 0
while len(queue) > 0:
    a = queue.popleft()
    time = a[1]
    name = a[0]

    if time > q:
        time -= q
        queue.append([name, time])
        t += q
    
    else:
        t += time
        print(a[0],t)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

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

queue = deque(A)
time_end = 0
ans_list = []
while len(queue) != 0:
    a = queue.popleft()
    if a[1] <= q:
        time_end += a[1]
        ans_list.append((a[0], time_end))
    else:
        time_end += q
        queue.append((a[0], a[1] - q))

for i in range(n):
    print(' '.join(map(str, ans_list[i])))

Submission status: Accepted

Solution code:
head = 0
tail = 0
max_i = 200000
elapsed_time = 0

def initialize():
  global head, tail
  head = tail = 0

def isEmpty():
  global head, tail
  return head == tail

def isFull():
  global head, tail, max_i
  return head == (tail + 1) % max_i

def enqueue(x):
  if isFull():
    print('over flow')
  global head, tail
  Q[tail] = x
  if tail + 1 == max_i:
    tail = 0
  else:
    tail += 1

def dequeue():
  if isEmpty():
    print('under flow')
  global head, tail
  x = Q[head]
  if head + 1 == max_i:
    head = 0
  else:
    head += 1
  return x

initialize()

N, q = map(int, input().split())
max_i = N + 2
Q = [('', 0) for i in range(max_i)]
for i in range(N): # 値を受け取り、tailを一つずらす
  Q[i] = list(input().split())
  Q[i][1] = int(Q[i][1])
  tail += 1

while (head != tail): # headがtailに追いつくまで
  task = dequeue()
  count = min(q, task[1])
  task[1] -= count
  elapsed_time += count
  if task[1] > 0:
    enqueue(task)
  else:
    print(f"{task[0]} {elapsed_time}")

Submission status: Accepted

Solution code:
class queue():
    def __init__(self):
        self.Q = []
    
    def enqueue(self, x):
        self.Q.append(x)
        
    def dequeue(self):
        return self.Q.pop(0)
    
    def isEmpty(self):
        if len(self.Q) == 0:
            return True
        else:
            return False
    
n, q = map(int, input().split())
RRS = queue()
for _ in range(n):
    prcs = input().split()
    RRS.enqueue([prcs[0], int(prcs[1])])

time = 0
while True:
    if RRS.isEmpty():
        break
    prcs = RRS.dequeue()
    c = min(prcs[1], q)
    prcs[1] -= c
    time += c
    if prcs[1] > 0:
        RRS.enqueue(prcs)
    else:
        print(prcs[0], time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
process = deque([tuple(map(str, input().split())) for _ in range(n)])

answer = []
time_count = 0
while process:
    name, time = process.popleft()
    time = int(time)

    if time - q > 0:
        time_count += q
        process.append((name, time - q))
    else:
        time_count += time
        answer.append((name, time_count))

for process in answer:
    name, time = process
    print(name, time)

Submission status: Accepted

Solution code:
from collections import deque

N,q = map(int,input().split())
stack = deque()
#lst = list(map(int, [input() for i in range(N)]))
stack.extend(list(input().split() for i in range(N)))
cnt = 0
endtime = deque()
while True:
    if len(stack) == 0:
        break
    x = stack.popleft()
    x[1] = int(x[1])
    if x[1] <= q:
        cnt += x[1]
        endtime.append([x[0],cnt])
    else:
        cnt += q
        x[1] -= q
        stack.append(x)


#print(" ".join(map(str,endtime)))
for i in endtime:
    print("{} {}".format(i[0],i[1]))

Submission status: Accepted

Solution code:
class Queue:
    def __init__(self) -> None:
        self.queue = list()

    def _is_empty(self):
        if len(self.queue) == 0:
            return True
        return False

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

    def dequeue(self):
        if self._is_empty():
            return None
        else:
            return self.queue.pop(0)

    def __len__(self):
        return len(self.queue)


def main():
    n, q = map(int, input().split(' '))
    queue = Queue()
    for i in range(n):
        name, num = input().split(' ')
        queue.enqueue({'name': name, 'num': int(num)})
    time = 0
    while True:
        if len(queue) == 0:
            break
        task = queue.dequeue()
        task['num'] -= q
        if task['num'] > 0:
            queue.enqueue(task)
            time += q
        else:
            time += q+task['num']
            print(task['name'], time)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def Initialize(head, tail):
    head, tail = 0, 0
    return head, tail

def IsEnpty(head, tail):
    return head == tail

def IsFull(head, tail):
    global MAX
    return head == (tail + 1) % MAX

def Enqueue(Q, x, y, head, tail):
    global MAX
    if IsFull(head, tail):
        return None
    Q[tail][0], Q[tail][1] = x, y
    if tail + 1 == MAX:
        tail = 0
    else:
        tail += 1
    return head, tail

def Dequeue(Q, head, tail):
    global MAX
    if IsEnpty(head, tail):
        return None
    x, y = Q[head][0], Q[head][1]
    if head + 1 == MAX:
        head = 0
    else:
        head += 1
    return x, y, head, tail

n, q = map(int, input().split())
MAX = n + 2
Q = [['', 0] for _ in range(MAX)]
head, tail = 0, 0
result = []
z = 0
for i in range(n):
    x, y = input().split()
    head, tail = Enqueue(Q, x, int(y), head, tail)
while IsEnpty(head, tail) != True:
    if Q[head][1] <= q:
        x, y, head, tail = Dequeue(Q, head, tail)
        result.append([x, y + z])
        z += y
    else:
        Q[head][1] -= q
        x, y, head, tail = Dequeue(Q, head, tail)
        head, tail = Enqueue(Q, x, y, head, tail)
        z += q
for i in range(n):
    print(*result[i], sep=' ')

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
li = []
for i in range(n):
    p, ms = map(str, input().split())
    li.append([p, int(ms)])
t = 0
out = []
while True:
    if(len(out)==n):
        break
    a = li.pop(0)
    p, ms = a[0], a[1]
    if(ms <= q):
        t += ms
        out.append([p, t])
    else:
        ms -= q
        t += q
        li.append([p, ms])

for i in range(n):
    print(out[i][0], out[i][1])

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
P = []
T = []
for i in range(n):
    p, t = map(str, input().split())
    P.append(p)
    T.append(int(t))

EndP = []
EndT = []
time = 0
while True:
    if T==[]:
        break
    
    if T[0]>q:
        T.append(T[0]-q)
        T.pop(0)
        P.append(P[0])
        P.pop(0)
        time += q
    
    if T[0]<=q:
        EndP.append(P[0])
        P.pop(0)
        time += T[0]
        EndT.append(time)
        T.pop(0)

for i in range(n):
    print(EndP[i],EndT[i])

Submission status: Accepted

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

Queue = []
for _ in range(n):
    tmp = input().split()
    name = tmp[0]
    time = int(tmp[1])
    Queue.append([name,time])

count = 0

while Queue:
    name = Queue[0][0]
    time = Queue[0][1]

    if time > q:
        Queue[0][1] -=q
        Queue.append(Queue.pop(0))

        count += q
    else:
        print(name,time+count)
        Queue.pop(0)
        count += time

Submission status: Accepted

Solution code:
from collections import deque


def main():
    n, q = [int(i) for i in input().split()]
    P = [input().split() for i in range(n)]
    process = deque()
    process.extend([
        {'name': p[0], 'time': int(p[1])}
        for p in P
    ])
    sum_time = 0
    while len(process):
        p = process.popleft()
        if p['time'] <= q:
            sum_time += p['time']
            print(p['name'], sum_time)
        else:
            sum_time += q
            p['time'] -= q
            process.append(p)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
LEN = 100005

n, q = map(int, input().split())
name = [None] * LEN
time = [None] * LEN

for i in range(n):
  name[i], time[i] = map(str, input().split())

head = 0
tail = n
curr = 0
done = 0

while True:
  if int(time[head]) > q:
    name[tail] = name[head]
    time[tail] = int(time[head]) - q
    curr += q

    if LEN == head + 1:
      head = 0
    else:
      head += 1

    if LEN == tail + 1:
      tail = 0
    else:
      tail += 1
    
  else:
    # Process done
    done += 1
    curr += int(time[head])
    print("{} {}".format(name[head], curr))

    if (done == n):
      break

    if LEN == head + 1:
      head = 0
    else:
      head += 1

Submission status: Accepted

Solution code:
## import sys

class queue:
    def __init__(self, length):
        self.max = length + 2
        self.v = list(range(self.max))
        self.head = 0
        self.tail = 0
        
    def enqueue(self, x):
        self.v[self.tail] = x
        self.tail = (self.tail+1) % self.max
        
    def dequeue(self):
        a = self.v[self.head]
        self.head = (self.head+1) % self.max
        
        return a
    
    
    def isEmpty(self):
        return self.head == self.tail
    
    def isFull(self):
        return (self.tail - self.head) == self.length
    
    
def main():
    n, q = list(map(int,input().split()))
    que = queue(n)
    for _ in range(n):
        lis = input().split()
        lis[1] = int(lis[1])
        
        que.enqueue(lis)
    
    time = 0
    while n > 0:
        now = que.dequeue()
        if now[1] > q:
            now[1] -= q
            que.enqueue(now)
            time += q
            
        else:
            time += now[1]
            print(now[0], time)
            n -= 1
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
procs = deque([name, int(time)] for name, time in [input().split() for _ in range(n)])

tot_time = 0
while procs:
  name, time = procs.popleft()
  if time <= q:
    tot_time += time
    print(name, tot_time)
  else:
    tot_time += q
    procs.append([name, time - q])

Submission status: Accepted

Solution code:
from collections import deque

n,q = map(int,input().split())
a = deque(list(input().split()) for _ in range(n))
total = 0

while a:
    b = a.popleft()
    b[1] = int(b[1])
    if b[1] > q:
        b[1] -= q
        a.append(b)
        total += q
    else:
        total += b[1]
        b[1] = total
        print(*b)

Submission status: Accepted

Solution code:
from collections import deque

n,q = map(int,input().split())
queue = deque([])

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

t = 0
while len(queue) > 0:
  top = queue.popleft()
  spend = min(top[1], q)
  top[1] -= spend
  t += spend
  if top[1] == 0:
    print(top[0], t)
  else:
    queue.append(top)

Submission status: Accepted

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

    def isEmpty(self):
        return self.head == self.tail 
    
    def isFull(self):
        return self.head == (self.tail +1)%self.size

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

    def dequeue(self):
        x = self.queue[self.head]
        if self.head + 1 == self.size:
            self.head = 0
        else:
            self.head += 1

        return x

num = 100000
que = queue(num)
time = 0

n, q = map(int, input().split())
for i in range(n):
    p, t = input().split()
    que.enqueue([int(t),p])

while not que.isEmpty():
    pt = que.dequeue()
    if pt[0] > q:
        time += q
        pt[0] -= q
        que.enqueue(pt)
    
    else:
        time += pt[0]
        print(pt[1], time)

Submission status: Accepted

Solution code:
from collections import deque

n,p=map(int ,input().split())
que=deque([])

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

t=0
while len(que)>0:
    atop=que.popleft()
    spend=min(atop[1],p)
    atop[1]-=spend
    t+=spend
    if(atop[1]==0):
        print(atop[0],t)
    else:
        que.append(atop)

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
s=[]
for i in range(a):
    name, time = input().split()
    time = int(time)
    s.append([name,time])
time=0
while True:
    if len(s)==0:
        break
   
    if s[0][1]>b:
        s[0][1]-=b
        s.append(s[0])
        s.pop(0)
        time+=b
    else:
        time=time+s[0][1]
        print("{} {}".format(s[0][0],time))
        s.pop(0)

Submission status: Accepted

Solution code:
import sys
MAX = 100005
n, q = map(int, input().split())

def initialize():
    head = tail = 0
    return head, tail

def isEmpty(head, tail):
    return head == tail

def isFull(head, tail):
    return head == (tail + 1) % MAX

def enqueue(x, head, tail):
    if isFull(head, tail):
        print('Error')
        sys.exit()
    Q[tail] = x
    if tail + 1 == MAX:
        tail = 0
    else:
        tail += 1
    return tail

def dequeue(head, tail):
    if isEmpty(head, tail):
        sys.exit()
    x = Q[head]
    if head + 1 == MAX:
        head = 0
    else:
        head += 1
    return x, head

head, tail = initialize()
Q = [0] * MAX
for _ in range(n):
    name, time = map(str, input().split())
    time = int(time)
    tail = enqueue([name, time], head, tail)
T = 0
while True:
    Qi, head = dequeue(head, tail)
    name = Qi[0]
    time = Qi[1]
    if time <= q:
        T += time
        print(name, T)
    else:
        T += q
        time -= q
        tail = enqueue([name, time], head, tail)

Submission status: Accepted

Solution code:
from collections import deque #シーケンスのどちらの端でも要素を追加、削除できるようにしたいときに便利

number_of_execution, rotation_time = map(int, input().split())
queue = deque([])  #順番を作る為、１x複数の行列

for i in range(number_of_execution):
    process_name, execution_time = input().split()
    time = int(execution_time)
    queue.append([process_name, time])

passed_time = 0
while len(queue) > 0:
    running_process = queue.popleft()
    passed_time += min(running_process[1], rotation_time)
    running_process[1] -= rotation_time
    if running_process[1] > 0:
        queue.append(running_process)
    else:
        print('{} {}'.format(running_process[0], passed_time))

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, val, next_node = None):
        self.value = val
        self.next = next_node
        
class que:
    def __init__(self):
        self.start = None
        self.last = None
    def append(self, num):
        new_node = Node(num)
        if self.start == None:
            self.start = new_node
            self.last = new_node
        else:
            self.last.next = new_node
            self.last = new_node
    def popleft(self):
        return_node = self.start
        self.start = return_node.next
        return return_node.value
    def isempty(self):
        return self.start == None
    def print_vals(self):
        node = self.start
        output =""
        while node != None:
            output += str(node.value)
            node = node.next
        print(output)
        
       
n, p = map(lambda x:int(x), input().split(' '))
processes = que()
for i in range(n):
    name, time = input().split(' ')
    time = int(time)
    processes.append((name, time))
all_time = 0
while not processes.isempty():
    name, time = processes.popleft()
    if time <= p:
        all_time += time
        print(f'{name} {all_time}')
    else:
        all_time += p
        processes.append((name, time - p))

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
prcs = []
for _ in range(n):
    nm, tm = input().split()
    prcs.append([nm, int(tm)])
elps = 0
while prcs != []:
    tmp = prcs.pop(0)
    if tmp[1] - q > 0:
        tmp[1] = tmp[1] - q
        prcs.append(tmp)
        elps += q
    else:
        elps += tmp[1]
        print(tmp[0], elps)

Submission status: Accepted

Solution code:
from collections import deque

n, q = map(int, input().split())
que = deque([])
for _ in range(n):
    key, value = input().split()
    que.append([key, int(value)])
    
t = 0
que_2 = []
while True:
    # print(que)
    if que[0][1] > q:
        t += q
        new = [que[0][0], que[0][1] - q]
        que.popleft()
        que.append(new)
    else:
        t += que[0][1]
        new_2 = [que[0][0], t]
        que_2.append(new_2)
        que.popleft()
        if len(que) == 0:
            break
        
for i in range(n):
    print(que_2[i][0], que_2[i][1])

Submission status: Accepted

Solution code:
from collections import deque
n, q_time = map(int, input().split())
d = deque()
for i in range(n):
    x, y = input().split()
    d.append((x, int(y)))

total = 0
while d:
    name, time = d.popleft()
    if time <= q_time:
        total += time
        print(name, total)
    else:
        total += q_time
        time -= q_time
        d.append((name, time))

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    que = queue.Queue()
    process_end = []

    for n in range(N):
        name, time = sl()
        que.put([name, int(time)])

    end_time = 0
    while not que.empty():
        name, time = que.get()
        if time > Q:
            end_time += Q
            que.put([name, time - Q])
        else:
            end_time += time
            process_end.append([name, end_time])

    for p in process_end:
        print(*p)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import queue

A = queue.Queue()
n, q = map(int, input().split())
for i in range(n):
    name, time = input().split()
    A.put([name, int(time)])
t = 0

while  not A.empty():
    L = A.get()
    if L[1] > q:
        L[1] -= q
        A.put(L)
        t += q
    else:
        t += L[1]
        print(L[0], t)

Submission status: Accepted

Solution code:
from collections import deque
d = deque()
n, quantum = map(int,input().split())
for i in range(n):
    n, t = input().split()
    d.append([n, int(t)])

total_flame = 0
while d:
    processing = d.popleft()
    if processing[1] <= quantum:
        print(processing[0], total_flame + processing[1])
        total_flame += processing[1]
    else:
        d.append([processing[0],processing[1]-quantum])
        total_flame += quantum

Submission status: Accepted

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

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

while processes:
    process = processes.pop(0)
    if process[1] <= q:
        elapse += process[1]
        result.append([process[0], elapse])
    else:
        elapse += q
        processes.append([process[0], process[1]-q])

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

from collections import deque

def main():
    tasks={}
    task_number,quantum = map(int,input().split())
    tasks=list(input().split() for _ in range(task_number))
    q = deque()
    calculate_time=0
    for i in range(task_number):
        q.append(tasks[i])
    while len(q) > 0:
        value = q.popleft()
        if quantum < int(value[1]):
            tmp=int(value[1])-quantum
            value[1]=tmp
            q.append(value)
            calculate_time+=quantum
        else:
            calculate_time+=int(value[1])
            print(value[0],calculate_time)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import queue

d = input().split(" ")

num = int(d[0])          # num of input data
threshold = int(d[1])

input_data = []
for i in range(num):
    input_data.append(input())

total_time = 0

# put all data in queue
q = queue.Queue()
for data in input_data:
    q.put(data)

while not q.empty():
    p = q.get().split(" ")
    p_name = p[0]
    p_time = int(p[1])

    # processing is not completed
    if p_time > threshold:   # 
        q.put(p_name + " " + str(p_time - threshold))
        total_time += threshold
    # processing is completed
    else:
        total_time += p_time
        print(p_name + " " + str(total_time))

Submission status: Accepted

Solution code:
from collections import deque

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

queue = deque()
for index in range(n):
    name, size = input().split()
    queue.append([name, int(size)])

time = 0
while len(queue) > 0:
    item = queue.popleft()
    if item[1] > limit:
        item[1] -= limit
        queue.append(item)
        time += limit
    else:
        time += item[1]
        print(" ".join([item[0], str(time)]))

Submission status: Accepted

Solution code:
from collections import deque

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

time = 0
while len(queue) != 0:
    name, t = queue.popleft()
    if t > q:
        queue.append((name, t - q))
        time += q
    elif t <= q:
        time += t
        print(name, time)

Submission status: Accepted

Solution code:
from collections import deque
import sys

input= sys.stdin.readline

n,q = [int(i) for i in input().strip().split()]

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

current_time = 0

while jobs:
    name,time = jobs.popleft()
    if time > q:
        jobs.append((name,time - q))
        current_time += q
    else:
        current_time += time
        print(name, current_time)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

def main():
    process_num, max_q_time = map(int, input().split())
    r_schedule_lst = deque([])
    for i in range(0, process_num):
        r_schedule_lst.append(list(input().split()))
    
    current_process = []
    elapsed_time = 0
    res = []
    while r_schedule_lst:
        cur_process = list(r_schedule_lst.popleft())
        cur_process_name = cur_process[0]
        cur_process_time = int(cur_process[1])
        
        remaining_time = cur_process_time - max_q_time
        if remaining_time > 0:
            elapsed_time += max_q_time
            r_schedule_lst.append([cur_process_name, remaining_time])
        else:
            elapsed_time += cur_process_time
            res.append([cur_process_name, elapsed_time])
        
    for n, t in res:
        print(n, t)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from copy import deepcopy


def round_robin(l, q):
    work = deepcopy(l)
    res = []
    time = 0
    while len(work):
        if work[0][1] > q:
            work[0][1] -= q
            work.append(work.pop(0))
            l.append(l.pop(0))
            time += q
        else:
            time += work[0][1]
            work.pop(0)
            res.append(l.pop(0))
            res[-1][1] = time
    return res


if __name__ == '__main__':
    n, q = list(map(int, input().split()))
    d = [list(map(lambda x: int(x) if x.isnumeric() else x, input().split())) for _ in range(n)]
    res = round_robin(d, q)
    for i in res:
        print(i[0],i[1])

Submission status: Accepted

Solution code:
import sys

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

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

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

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

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

process_list = []
for n in range(N):
    p,time = input().split(" ")
    process_list.append([p,int(time)])

Q = Queue()
for p in process_list:
    Q.enqueue(p)

elapsed_time = 0
while not Q.isEmpty():
    process = Q.dequeue()
    if process[1] > q:
        elapsed_time += q
        Q.enqueue([process[0],process[1]-q])
    else:
        elapsed_time += process[1]
        print(process[0]+" "+str(elapsed_time))

Submission status: Accepted

Solution code:
n,q=input().split()
n=int(n)
q=int(q)
p_list=[]
timer=0
head=0
tail=n
for i in range(0,n):
    tmp=input()
    p_list.append([tmp.split()[0],int(tmp.split()[1])])
p_list.append("NULL")

def deque():
    global head
    tmp=p_list[head]
    head=(head+1)%(n+1)
    return tmp

def enque(x):
    global tail
    p_list[tail]=x
    tail=(tail+1)%(n+1)

while(head!=tail):
    elem=deque()
    timer+=min(elem[1],q)
    elem[1]-=min(elem[1],q)
    if elem[1]>0:
        enque(elem)
    else:
        print(str(elem[0])+" "+str(timer))

Submission status: Accepted

Solution code:
import collections
head = 0
tail = 0


def queue_put(q, a):
    global tail
    q[tail] = a
    tail = (tail + 1) % len(q)


def queue_get(q):
    global head
    result = q[head]
    head = (head + 1) % len(q)
    return result


Q = collections.namedtuple("Q", "nm tm")
n, period = map(int, input().split())

q = ["" for _ in range(n + 1)]
for i in range(n):
    nm, tmp = input().split()
    tm = int(tmp)

    queue_put(q, Q(nm, tm))

tm = 0
while head != tail:
    a = queue_get(q)

    d = min(period, a.tm)
    tm += d
    a = a._replace(tm=a.tm - d)

    if a.tm == 0:
        print(a.nm, tm)
    else:
        queue_put(q, a)

Submission status: Accepted

Solution code:
from collections import deque


n, q = map(int, input().split())
process = deque()
now = 0

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

while process:
    task = process.popleft()
    now += min(q, task[1])
    if q < task[1]:
        process.append([task[0], task[1] - q])
    else:
        print(task[0], now)

Submission status: Accepted

Solution code:
from collections import deque
n, q = input().rstrip().split(" ")
n = int(n)
q = int(q)

processes = deque()
now_time = 0

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

while len(processes) >= 1:
    current_processes = processes.popleft()
    if current_processes[1] > q:
        current_processes[1] -= q
        now_time += q
        processes.append(current_processes)
    else:
        now_time += current_processes[1]
        print(current_processes[0] + " " + str(now_time))

Submission status: Accepted

Solution code:
from collections import deque

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

d = deque()
d.extend(name_time)

total_time = 0

while d:
    name, time = d.popleft()
    time = int(time)
    if time <= q:
        total_time += time
        print(name, total_time)
    else:
        total_time += q
        d.append([name, str(time-q)])