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:
class queue():
    def __init__(self,size,q):
        self.time={}
        self.finishlist=[]
        self.S=[None]*size
        self.q=q
        self.under=0#最後の要素
    def print(self):
        print(self.under)

    def enqueue(self,x):#FI
        self.under+=1
        self.S[self.under]=x
    def unqueue(self):#FO
        self.under-=1
        vari=self.S[1]
        del self.S[1]
        self.S.append(None)
        return vari
    def isEmpty(self):
        return self.under!=0
    def calc(self):
        alltime=0
        while(self.isEmpty()):
            process=self.unqueue()
            da=int(process[1])
            if int(process[1])>self.q:
                # if process[0] not in self.time:
                #     self.time[process[0]]=self.q
                # else:
                #     self.time[process[0]] += self.q
                alltime+=self.q
                da-=self.q
                (process[1])=str(da)
                self.enqueue(process)
            else:#処理終了
                alltime+=int(process[1])
                self.time[process[0]] = alltime


                self.finishlist.append(process[0])
        return self.time,self.finishlist

size,q=[int(x) for x in input().split()]
que=queue(size+1,q)
# [que.enqueue(x) for x in input().split()]
[que.enqueue(input().split()) for x in range(size)]
time,finishhantei=que.calc()
for name in finishhantei:
    print(name,time[name])

Submission status: Accepted

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

name = ['' for i in range(n)]
time = [0 for i in range(n)]
for i in range(n):
    x,y = input().split()
    name[i] = x
    time[i] = int(y)

ttl = 0
while 1:
    if len(name) == 0:
        break
    if time[0] - q <= 0:
        ttl += q - (q - time[0])
        ptime = ttl
        print(name[0],ptime)
        del name[0]
        del time[0]
    else:
        ttl += q
        time[0] -= q
        name.append(name[0])
        time.append(time[0])
        del name[0]
        del time[0]

Submission status: Accepted

Solution code:
# Queue キュー
class Queue():
    def __init__(self, size):
        self.size = size
        self.Q = [None for i in range(size)]
        self.top = 0
        self.btm = 0
    
    def enqueue(self, x):
        self.Q[self.btm] = x;
        self.btm += 1;
        if self.btm >= self.size:
            self.btm = 0
    
    def dequeue(self):
        ret = self.Q[self.top]
        self.Q[self.top] = None
        self.top += 1
        if self.top >= self.size:
            self.top = 0
        return ret
    
    def __repr__(self):
        list(self.Q)
    
class Process():
    def __init__(self, name, time):
        self.name = name
        self.time = time
    
    def getname(self):
        return self.name
    
    def proceed(self, q):
        if q <= self.time:
            self.time -= q
            return q;
        elif q > self.time:
            ret = self.time
            self.time = 0
            return ret
    
    def isFinished(self):
        return self.time == 0
    
    def __repr__(self):
        return self.name + " " + str(self.time)

n, q = (int(i) for i in input().split())
Q = Queue(n)
for i in range(0,n):
    data = input().split()   
    name = data[0]
    time = int(data[1])
    Q.enqueue(Process(name, time))
timeelapsed = 0
while True:
    p = Q.dequeue()
    if p == None:
        break
    timeelapsed += p.proceed(q)
    if p.isFinished():
        print(p.getname(), timeelapsed)
    else:
        Q.enqueue(p)

Submission status: Accepted

Solution code:

n,p=map(int,input().split())
ps=[]
for i in range(n):
	ps.append(input().split())
	ps[i][1]=int(ps[i][1])
t=0
while len(ps)>0:
	if ps[0][1]>p:
		ps.append([ps[0][0],ps[0][1]-p])
		t+=p
		ps.pop(0)
	else:
		t+=ps[0][1]
		print("{0} {1}" .format(ps[0][0],t))
		ps.pop(0)

Submission status: Accepted

Solution code:
from collections import deque

def main():
    n,q = map(int,input().split())
    d = deque()
    for _ in range(n):
        p,t = input().split()
        d.append([p,int(t)])

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

N, q = map(int, input().split())
A = []
for i in range(N):
    s, a = input().split()
    A.append((s, int(a)))

queue = deque(A)
t = 0
while queue:
    s, a = queue.popleft()
    if a-q > 0:
        t += q
        queue.append((s, a-q))
    else:
        t += a
        print(s, t)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
# %%
class Queue:
    def __init__(self, size=100005):
        self.size = size
        self.q = [None] * self.size
        self.head = 1
        self.tail = 1

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

    def enqueue(self, obj):
        self.q[self.tail] = obj
        if self.tail == self.size - 1:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.head == self.size - 1:
            self.head = 0
            return self.q[self.size - 1]
        else:
            self.head += 1
            return self.q[self.head - 1]


qu = Queue()

li = list(map(int, input().split()))
n = li[0]
q = li[1]

for i in range(n):
    li = list(map(str, input().split()))
    li[1] = int(li[1])
    qu.enqueue(li)

# q = 100
# qu.enqueue(['p1', 150])
# qu.enqueue(['p2', 80])
# qu.enqueue(['p3', 200])
# qu.enqueue(['p4', 350])
# qu.enqueue(['p5', 20])

time = 0
while True:
    temp_list = qu.dequeue()
    temp_name = temp_list[0]
    temp_num = temp_list[1]
    if temp_num <= q:
        time += temp_num
        print(temp_name + ' {}'.format(time))
        if qu.is_empty():
            break
    else:
        li = [temp_name, temp_num - q]
        qu.enqueue(li)
        time += q

Submission status: Accepted

Solution code:
from collections import deque
d = deque()
time = dict()
complete = dict()
complete_time = 0
n, q = map(int, input().split())
for _ in range(n):
    process, msec = input().split()
    d.append(process)
    time[process] = int(msec)
while d:
    target_process = d.popleft()
    if time[target_process] <= q:
        complete_time += time[target_process]
        complete[target_process] = complete_time
    else:
        complete_time += q
        time[target_process] -= q
        d.append(target_process)

for key, value in complete.items():
    print(key, value)

Submission status: Accepted

Solution code:
'''
Pythonのリストはappend, popなどを末尾の要素に対して実行するのは早いが、先頭への挿入や取り出しは遅い。
collections.dequeを使えば両端に対する操作を効率的に実行可能。enqueueはappend, dequeueはpopleftを使う。
'''
from collections import deque
n, q = map(int, input().split())
L = []
for i in range(n):
    a, b = input().split()
    L.append([a, int(b)])
L = deque(L)

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

Submission status: Accepted

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

que = []
for _ in range(n):
  name, total = raw_input().split()
  que += [[name, total]]

total = 0
answer = []

while que:
  
  item = que.pop(0)
  name, time = item[0], int(item[1])

  if time > q:
    que += [[name, time - q]]
    total += q
  else:
    total += time
    answer += [[name, str(total)]]

for w in answer:
  print ' '.join(w)

Submission status: Accepted

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

    def __str__(self):
        return str(self.time)


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

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

idx = 0
total = 0
while len(queue) > idx:
    time = queue[idx].time
    if time > q:
        total += q
        queue[idx].time -= q
        queue.append(queue[idx])
    else:
        total += time
        print(queue[idx].name + ' ' + str(total))

    idx += 1

Submission status: Accepted

Solution code:
N,q=list(map(int,input().split()))
name=[]
time=[]
sum_time=0

for n_temp in range(N):
    na,ti=input().split()
    name.append(na)
    time.append(int(ti))

while True:
#     print(time,name,ans_name)
    t = time.pop(0)
    n = name.pop(0)
    
    if t-q>0:
        time.append(t-q)
        name.append(n)
        sum_time+=q
    else:
        sum_time+=t
        print(n,sum_time)

    if len(name)<=0:
        break

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp

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

    def enqueue(self, x):
        self.list.append(x)
    
    def dequeue(self):
        return self.list.pop(0)
    
    def isEmpty(self):
        return len(self.list) == 0


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

    jobs = [input().split(' ') for _ in range(n)]


    for job in jobs:
        que.enqueue([job[0], int(job[1])])

    total = 0
    while not que.isEmpty():
        # print(que.list)

        name, time = que.dequeue()

        nokori = time - q
        if nokori > 0:
            total += q
            que.enqueue([name, nokori])
        else:
            total += time
            print(name, total)




main()

Submission status: Accepted

Solution code:
n, q = map(int, input().split())
process = [input().split() for _ in range(n)]
task = process[:]
cnt = 0
last = 0
while task:
    t = task.pop(0)
    name, time = t[0], int(t[1])
    if time <= q:
        cnt += time
        print(name, cnt)
    else:
        task.append([name, str(time - q)])
        cnt += q

Submission status: Accepted

Solution code:
import collections
n,q = map(int,input().split())
class deque():
  def __init__(self):
    self.a = [None]*100000
    self.head = 0
    self.tail = 0
  def append(self,e):
    self.a[self.tail] = e
    self.tail += 1
    if self.tail == 100000: self.tail = 1
  def __bool__(self):
    return self.head != self.tail
  def popleft(self):
    if self.head == self.tail:
      return None
    ret = self.a[self.head]
    self.head += 1
    if self.head == 100000: self.head = 1
    return ret
#a = collections.deque()
a = deque()
for i in range(n):
  name,time = input().split()
  a.append([name,int(time)])
rest = q
t = 0
while a:
  name,time = a.popleft()
  if q < time:
    t += q
    a.append([name,time-q])
  else:
    t += time
    print(name,t)

Submission status: Accepted

Solution code:
from collections import deque

dq = deque()
n, q = map(int, input().split())
for _ in range(n):
    name, time = input().split()
    dq.append((name, int(time)))
t = 0
while dq:
    name, time = dq.popleft()
    if time > q:
        dq.append((name, time - q))
        t += q
    else:
        t += time
        print(name, t)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
lst = deque([])
for i in range(n):
    name, time = input().split()
    lst.append({'name': name, 'time': int(time)})
now = 0
while len(lst) > 0:
    task = lst.popleft()
    now += min(q, task['time'])
    task['time'] -= q
    if task['time'] > 0:
        lst.append(task)
    else:
        print(task['name'], now)

Submission status: Accepted

Solution code:
class Node:
    __slots__ = ["data", "next", "prev"]
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = None

class Queue:
    __slots__ = ["head", "tail"]
    def __init__(self):
        self.head = None
        self.tail = None
    
    def appendleft(self, data):
        node = Node(data)
        self.head, node.next = node, self.head
        if self.tail:
            node.next.prev = self.head
        else:
            self.tail = node
    
    def pop(self):
        if self.tail:
            target, self.tail = self.tail, self.tail.prev
            if self.tail:
                self.tail.next = None
            return target.data

def simulate_round_robin_scheduling(x, y):
    total_time = 0
    while y.tail:
        name, time = y.pop()
        time = int(time)
        total_time += min(time, x)
        time -= x
        if time > 0:
            y.appendleft([name, time])
        else:
            print("{} {}".format(name, total_time))
if __name__ == "__main__":
    n, q = map(int, input().split())
    processes = Queue()
    for _ in range(n):
        processes.appendleft(input().split())
    simulate_round_robin_scheduling(q, processes)

Submission status: Accepted

Solution code:
from collections import deque

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

d = deque()
for i in l:
    d.append((i[0],int(i[1])))
t = 0

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

Submission status: Accepted

Solution code:
from collections import deque

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

name=deque()
time=deque()

for n in range(d):
    a,b=input().split()
    name.append(a)
    time.append(int(b))
    
ans=0
    
while name:
    n=name.popleft()
    t=time.popleft()
    if t>q:
        name.append(n)
        time.append(t-q)
        ans=ans+q
    else:
        ans=ans+t
        print(n,ans)

Submission status: Accepted

Solution code:
n,q=map(int, input().split())
queue=[]
for _ in range(n):
    name,time=map(str, input().split())
    queue.insert(0, {"name":name, "time":int(time)})

T=0
while queue != []:
    process=queue.pop()
    if process["time"] <= q:
        T+=process["time"]
        print(process["name"], T, sep=" ")
    else :
        process["time"]-=q
        queue.insert(0, process)
        T+=q

Submission status: Accepted

Solution code:
import collections

N, q = [int(item) for item in input().split()]
input_list = [[item for item in input().split()] for _ in range(N)]

que = collections.deque()
for p, time in input_list:
    que.append([p, int(time)])

finish_time = 0
while que:
    temp = que.popleft()

    if temp[1] - q <= 0:
        finish_time += temp[1]
        print(temp[0], finish_time)

    else:
        finish_time += q
        temp[1] -= q
        que.append(temp)

Submission status: Accepted

Solution code:
import sys
import math
import copy
from typing import Tuple, List, Union
input = sys.stdin.readline

class Process:
    def __init__(self, name: str, value: Union[int, str]):
        self.name = name
        self.value = int(value)
    def takes(self, quontum:int) -> Tuple[int, bool]:
        if self.value > quontum:
            self.value -= quontum
            return (quontum, True)
        else:
            return (self.value, False)

    def __repr__(self):
        return "{}-{}".format(self.name, self.value)


if __name__ == "__main__":
    queue = []
    n, q = map(int , input().split())
    for i in range(n):
        queue.append(Process(*input().split()))
    time = 0
    j = 0
    while len(queue):
        process = queue.pop(0)
        val, rest = process.takes(q)
        time += val
        if rest:
            queue.append(process)
        else:
            print(process.name,time)

Submission status: Accepted

Solution code:
#alds13a

class Task:
    def __init__(self,pid,rest_time):
        self.pid = pid
        self.rest_time=int(rest_time)

n,q = map(lambda x: int(x),input().split(" "))
tasks=[]
for i in range(n):
    A = input().split(" ")
    tasks.append(Task(A[0],A[1]))
    
time=0
while len(tasks)>0:
    t = tasks.pop(0)
    if t.rest_time<=q:
        time += t.rest_time
        print(t.pid,time)
    else:
        time += q
        t.rest_time -= q
        tasks.append(t)

Submission status: Accepted

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

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

while len(ps) > 0:
    if ps[0][1] <= q:
        total += ps[0][1]
        print(ps[0][0], total)
        del ps[0]
    else:
        total += q
        ps[0][1] -= q
        ps.append(ps[0])
        del ps[0]

Submission status: Accepted

Solution code:
class MyQueue:
    def __init__(self, max):
        self.MAX = max
        self.queue = [0] * self.MAX
        self.head = self.tail = 0
        
    def is_empty(self):
        return self.head == self.tail
        
    def is_full(self):
        return self.head == self.tail+1%self.MAX
        
    def enqueue(self, elm):
        if self.is_full():
            raise ValueError()
        
        self.queue[self.tail] = elm
        
        if self.tail+1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1
    
    def dequeue(self):
        if self.is_empty():
            raise ValueError()
        
        elm = self.queue[self.head]
        
        if self.head+1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        
        return elm

N, qt = [int(n) for n in input().split()]
queue = MyQueue(N+10)

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

time = 0
while not queue.is_empty():
    prc = queue.dequeue()
    if prc[1] > qt:
        prc[1] -= qt
        queue.enqueue(prc)
        time += qt
    else:
        time += prc[1]
        print(prc[0], time)

Submission status: Accepted

Solution code:
n,q = map(int, input().split())
P = {}
Q = []
for i in range(n):
    a,b = input().split()
    P[a] = int(b)
    Q.append(a)
time = 0

while len(Q) > 0:
    if P[Q[0]] > q:
        time += q
        P[Q[0]] -= q
        Q.append(Q[0])
    else:
        time += P[Q[0]]
        P[Q[0]] = 0
        print("{} {}".format(Q[0], time))
    Q.remove(Q[0])

Submission status: Accepted

Solution code:
from collections import deque
n, q = map(int, input().split())
d = deque()
e,a = 0,[]
for _ in range(n):
    m, t = input().split()
    d.append((m, int(t)))
while d:
    m, t = d.popleft()
    if t - q > 0:
        e += q
        d.append((m, t - q))
    else:
        e += t
        a += [f'{m} {e}']
print('\n'.join(a))

Submission status: Accepted

Solution code:
class Queue:
    def __init__(self):
        self.max = int(1e6)
        self.data = [0] * self.max
        self.head = 0
        self.tail = 0
    def isEmpty(self):
        return self.head == self.tail
    def isFull(self):
        return self.head == (self.tail + 1) % self.max
    def enqueue(self, x):
        try:
            if self.isFull():
                raise Exception('Queue is full')
            self.data[self.tail] = x
            if self.tail + 1 == self.max:
                self.tail = 0
            else:
                self.tail += 1
        except Exception as e:
            print(e)
    def dequeue(self):
        try:
            if self.isEmpty():
                raise Exception('Queue is empty')
            x = self.data[self.head]
            if self.head + 1 == self.max:
                self.head = 0
            else:
                self.head += 1
            return x
        except Exception as e:
            print(e)

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

n, q = map(int, input().split())
processes = Queue()
for i in range(n):
    name, time = input().split()
    time = int(time)
    processes.enqueue(Process(name, time))

totalTime = 0
finishedProcesses = 0

while finishedProcesses < n:
    runningProcess = processes.dequeue()
    if runningProcess.time <= q:
        totalTime += runningProcess.time
        runningProcess.time = 0
        runningProcess.endTime = totalTime
        finishedProcesses += 1
        print(runningProcess.name, runningProcess.endTime)
    else:
        totalTime += q
        runningProcess.time -= q
        processes.enqueue(runningProcess)

Submission status: Accepted

Solution code:

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

from collections import deque

ls = []
for i in range(n):
    ls.append(list(input().split()))

que = deque(ls)

elapse = 0
while len(que)>0:
    name, time = que.popleft()
    time = int(time)
    if time <= q:
        elapse += time
        print('%s %d'%(name, elapse))
    else:
        elapse += q
        time -= q
        que.append([name, time])

Submission status: Accepted

Solution code:
from collections import deque

n,q=map(int,input().split())
q = int(q)
queue=deque()
for i in range(n):
  queue.append(list(input().split()))

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

Submission status: Accepted

Solution code:
N, Q = map(int, input().split())
X = []
for i in range(0, N):
    x, y = map(str, input().split())
    X.append([x, int(y)])
ans = []
time = 0
while len(X) != 1:
    tmp = X.pop(0)
    if tmp[1] <= Q:
        time += tmp[1]
        ans.append([tmp[0], time])
    else:
        time += Q
        tmp[1] -= Q
        X.append(tmp)
ans.append([X[0][0], time+X[0][1]])
for i in range(0, N):
    print(ans[i][0], ans[i][1])

Submission status: Accepted

Solution code:
n, q = [int(i) for i in input().split(" ")]

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

et = 0
result = []
while len(queue) > 0:
    job = queue.pop(0)
    et += min(job[1], q)
    newJob = (job[0], job[1]-q)
    if newJob[1] > 0:
        queue.append(newJob)
    else:
        result.append((job[0], et))

for r in result:
    print(r[0] + " " + str(r[1]))

Submission status: Accepted

Solution code:
from queue import Queue

def main():
    N, Q = map(int, input().split())
    q = Queue()
    for n in range(N):
        name, time = input().split()
        q.put((name, int(time)))
    
    timer = 0
    while not q.empty():
        name, time = q.get()
        if time > Q:
            time -= Q
            timer += Q
            q.put((name, time))
        else:
            timer += time
            print("{} {}".format(name, timer))
            
            
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

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

class RoundRobin:
    def __init__(self):
        self.time = 0
        self.queue = deque()
        self.num_of_task, self.quantum = map(int, input().split())
        
    def enqueue(self, task):
        self.queue.append(task)
    
    def dequeue(self):
        return self.queue.popleft()


rr = RoundRobin()

for _ in range(rr.num_of_task):
    input_task = input().split()
    rr.enqueue(Task(input_task[0], int(input_task[1])))

while len(rr.queue) > 0:
    task = rr.dequeue()
    if task.cost <= rr.quantum:
        rr.time += task.cost
        print("%s %d"%(task.name, rr.time))
    else:
        task.cost -= rr.quantum
        rr.time += rr.quantum
        rr.enqueue(task)

Submission status: Accepted

Solution code:
from collections import deque

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

    finish = 0  # 終了時刻

    while len(q) > 0:
        top = q.popleft()  # 最も左側の要素を削除して返す
        s = min(top[1], t)  # クオンタムと先頭プロセスの残り時間の内，小さい方をsに代入
        top[1] -= s
        finish += s
        if top[1] == 0:
            print(top[0], finish)   # 終了プロセスと終了時刻を表示
        else:
            q.append(top)   # queueの後ろに追加

if "__main__" == __name__:
    n, t = map(int, input().split())
    queue(n, t)

Submission status: Accepted

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

answer = []
time = 0
while len(proc) != 0:
    target = proc.pop(0)

    if target[1] <= q:
        time += target[1]
        answer.append([target[0], time])
    else:
        time += q
        target[1] -= q
        proc.append(target)

[print(*answer[i]) for i in range(len(answer))]

Submission status: Accepted

Solution code:
from collections import deque

class process():
    def __init__(self, name, ptime):
        self.name = name
        self.ptime = ptime

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

    for _ in range(n):
        name, ptime = input().split()
        p = process(name, int(ptime))
        w_queue.append(p)

    t = 0

    while True:
        p = w_queue.popleft()
        
        if p.ptime <= q:
            print(p.name, str(t + p.ptime))
            t += p.ptime
        else:
            p.ptime -= q
            w_queue.append(p)
            t += q
       
        if len(w_queue) == 0:
            break
        
main()

Submission status: Accepted

Solution code:
from queue import Queue


def main():
    n, q = map(int, input().split(' '))
    process_time = Queue()
    process_name = Queue()
    for _ in range(n):
        name, time = input().split(' ')
        process_name.put(name)
        process_time.put(int(time))
    cnt_time = 0
    while not (process_time.empty()):
        time = process_time.get()
        if time <= q:
            cnt_time += time
            print(process_name.get(), cnt_time)
        else:
            cnt_time += q
            process_time.put(time - q)
            process_name.put(process_name.get())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

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

ps = deque()
for i in range(n):
  p = [ i for i in input().split(" ") ]
  ps.append([p[0], int(p[1])])

time = 0
while len(ps) > 0:
  p = ps.popleft()

  tmp = p[1] - q
  if tmp > 0:
    ps.append([p[0], tmp])
    time +=  q
  else:
    time += p[1]
    print(p[0], str(time))

Submission status: Accepted

Solution code:
import queue


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

    def __repr__(self):
        return '{} {}'.format(self.name, self.value)


Q = queue.Queue()

n, q = map(int, input().split())
for _ in range(n):
    name, value = input().split()
    Q.put(Process(name, int(value)))

t = 0
while not Q.empty():
    process = Q.get()
    if process.value > q:
        process.value -= q
        Q.put(process)
        t += q
    else:
        t += process.value
        print('{} {}'.format(process.name, t))

Submission status: Accepted

Solution code:
#初期dataの格納
input_number,input_time = map(int, input().split())
input_data = list()
for i in range(input_number):
    input_data.append(list(input().split()))
    input_data[i][-1] = int(input_data[i][-1])

#アルゴリズム実行
temp_list = list()
total_time = 0
result_list = list()
while len(input_data) > 0:
    temp_list = input_data[0]
    if temp_list[-1] > input_time:
        total_time += input_time
        temp_list[-1] -= input_time
        input_data.append(temp_list)
    else:
        total_time += temp_list[-1]
        temp_list[-1] = total_time
        result_list.append(temp_list)
    del input_data[0]

#結果の表示
[print(" ".join(map(str, i))) for i in result_list]

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[input().split() for _ in range(n)]
cnt=0
while(p):
    if int(p[0][1])>m:
        p[0][1]=int(p[0][1])-m
        x=p[0]
        del(p[0])
        p.append(x)
        cnt+=m
    else:
        cnt+=int(p[0][1])
        print(p[0][0], cnt)
        del(p[0])

Submission status: Accepted

Solution code:
def show(a):
    print(a[0], a[1], sep = ' ')


l = input().split()
n = int(l[0])                  
q = int(l[1])                  

list_a = []
for i in range(n):
    a = input().split()
    list_a.append(a) 

time = 0          

while len(list_a) != 0:
    if int(list_a[0][1]) > q:
        time += q 
        list_a[0][1] = (int(list_a[0][1]) - q)
        a = list_a.pop(0)
        list_a.append(a)
    else :
        time += int(list_a[0][1])
        list_a[0][1] = time
        a = list_a.pop(0)
        show(a)

Submission status: Accepted

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

que = deque([])
for _ in range(n):
    que.append((int(x) if x.isdigit() else x for x in input().split()))
    
lap = 0

while que:
    name, lefttime = que.popleft()
    if lefttime <= q:
        lap += lefttime
        print(name, lap)
    else:
        lefttime -= q
        lap += q
        que.append((name, lefttime))