Problem:
There are n processes in a queue. Each process has name i and time i .  The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80) - C(200) - D(200) First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms). B(80) - C(200) - D(200) - A(50) Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue. C(200) - D(200) - A(50) Your task is to write a program which simulates the round-robin scheduling .  Input  n  q  name 1 time 1  name 2 time 2 ...  name n time n  In the first line the number of processes n and the quantum q are given separated by a single space. In the following n lines, names and times for the n processes are given. name i and time i are separated by a single space. Output For each process, prints its name and the time the process finished in order. Constraints  1 ≤ n ≤ 100000  1 ≤ q ≤ 1000  1 ≤ time i ≤ 50000  1 ≤ length of name i ≤ 10  1 ≤ Sum of time i ≤ 1000000  Sample Input 1 5 100
p1 150
p2 80
p3 200
p4 350
p5 20 Sample Output 1 p2 180
p5 400
p1 450
p3 550
p4 800 Notes Template in C

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

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

Solution (Python):
n,q=map(int,input().split())
tasknums=[]
times=[]
finish_task=[]
finish_time=[]
take=0
for i in range(0,n):
    a,b=input().split()
    tasknums.append(a)
    times.append(int(b))
while tasknums:
    tasknum=tasknums.pop(0)
    time=times.pop(0)
    if time>q:
        time-=q
        tasknums.append(tasknum)
        times.append(time)
        take+=q
    else:
        finish_task.append(tasknum)
        finish_time.append(take+time)
        take+=time
for i in range(0,n):
    print(finish_task[i]+" "+str(finish_time[i]))

Solution (Python):




class Process:
    def __init__(self, line):
        self.name = line[0]
        self.time = int(line[1])


LEN = 100000
n = 0
head = 0
tail = 0
Q = [0] * LEN


def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN

def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x


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

    global head, tail

    elaps = 0
    while(head != tail):
        u = dequeue()
        c = min(q, u.time)
        u.time -= c
        elaps += c
        if u.time > 0:
            enqueue(u)
        else:
            print(u.name, elaps)

if __name__ == '__main__':
    main()

Solution (Python):
n, q = map(int, input().split())
queue = [input() for i in range(n)]
cnt = 0
while len(queue) != 0:
    name, time = queue.pop(0).split()
    if int(time) <= q:
        cnt+=int(time)
        print(name,str(cnt))
    else:
        cnt+=q
        time = str(int(time) - q)
        queue.append(name+" "+time)

Solution (Python):




from queue import Queue
n,q=map(int,input().split())
que=Queue()

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

total=0
while que.qsize()>0:
    name,time = que.get()
    total += min(q,time)
    if q < time:
        que.put((name,time-q))
    else:
        print(name,total)

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

Solution (Python):
from collections import deque
import sys
n, q = map(int, input().split())
queue = deque([])
for _ in range(n):
    name, time = input().split()
    time = int(time)
    queue.append([name, time])
time = 0
while True:
    try:
        if queue[0][1] <= q:
            time += queue[0][1]
            print(queue[0][0], time)
            queue.popleft()
        else:
            time += q
            queue[0][1] -= q
            queue.rotate(-1)
    except:
        sys.exit()

Solution (Python):
n, q = map(int, input().split())
p = []
for i in range(n):
    p_tmp = input().split()
    p.append([p_tmp[0], int(p_tmp[1])])



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

Solution (Python):
from collections import deque
 
n, q = map(int,(input().split()))
queue = deque()
 
for i in range(n):
    name, time = input().split()
    queue.append( [name, int(time)]  )
     
t = 0
while queue:
    p = queue.popleft()
    t += min(q, p[1])
    if q < p[1]:
        queue.append([p[0], p[1] - q])
    else:
        print(f"{p[0]} {t}")

Solution (Python):
from collections import deque

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

a = deque()
for _ in range(n):
    t = (input().split(' '))
    t[1] = int(t[1])
    a.append(t)

b = deque()
s = 0
while len(a) != 0:
    t = a.popleft()
    if t[1] - q <= 0:
        b.append((t[0], t[1] + s))
        s += t[1]
    else:
        t[1] -= q
        s += q
        a.append(t)

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

Solution (Python):
from collections import deque

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

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

total = 0
while alist:
    curr = iter(alist)
    ob = next(curr)
    res = int(ob[1]) - q
    if res > 0:
        total += q
        ob[1] = res
        alist.append(ob)
        alist.popleft()
    else:
        total += q + res
        ob[1] = total
        endlist.append(ob)
        alist.popleft()

for x in endlist:
    print('{} {}'.format(x[0], x[1]))

Solution (Python):



from collections import deque

def main():
    n, q = [int(x) for x in input().split()]

    proc = deque()

    for i in range(n):
        name, ptime = input().split()
        proc.appendleft((name, int(ptime)))

    time = 0
    while proc:
        name, ptime = proc.pop()
        time += min(q, ptime)
        ptime -= min(q, ptime)
        if ptime <= 0:
            print(name, time)
        else:
            proc.appendleft((name, ptime))

main()

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

Q = []


for i in range(n):
    process, time = input().split(" ")
    Q.append([process,int(time)])
    
total_time = 0

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

Solution (Python):

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

list=[]
for i in range(n):
    x=input().split(" ")
    p=x[0]
    time=int(x[1])
    list.append([p,time])
 
time=0
while len(list)>0:
    if list[0][1]<=q:
        time+=list[0][1]
        print(list[0][0]+" "+str(time))
        list.pop(0)
    else:
        time+=q
        list[0][1]-=q
        list.append(list[0])
        list.pop(0)

Solution (Python):
from collections import deque

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


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

end_time = 0
while len(queue) > 0:
    p = queue.popleft()
    if p.time > q:
        p.time -= q
        end_time += q
        queue.append(p)
    else:
        end_time += p.time
        print('%s %d' % (p.name, end_time))

Solution (Python):
from collections import deque

def print_dict_multi_low(a_dict):
    for k, v in a_dict.items():
        print("{0} {1}".format(k, v))
        
def calc_round_robin(A, q):
    t = 0
    B = {}
    queue = deque([])
    for k, v in A.items():
        queue.append((k, v))
    
    while queue:
        k, v = queue.popleft()
        residual = int(v) - q
        if residual > 0:
            queue.append((k, residual))
            t += q
        else:
            t += (q + residual)
            B[k] = t
    print_dict_multi_low(B)

def read_n_lows_dict_input(n):
    a_dict = dict(input().split() for _ in range(n))
    return a_dict

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

calc_round_robin(A, q)

Solution (Python):
n, q = list(map(int, input().split()))
works = []
for i in range(n):
    works.append(list(input().split()))
 
count = 0
while len(works) != 0:
    work = works.pop(0)
    time = int(work[1])
    if time > q:
        count += q
        work[1] = time - q
        works.append(work)
    else:
        count += time
        print(work[0] , count)

Solution (Python):
from collections import deque
n, q = list(map(int, input().split()))
que = deque([])
for i in range(n):
  n, t = input().split()
  que.append((n, t))

e = 0
while len(que)>0:
  n, t = que.popleft()
  if int(t)<=q:
    e += int(t)
    print(n, e)
  else:
    e += q
    que.append((n, int(t)-q))

Solution (Python):

class Proc:
    def __init__(self, strs):
        self.name = strs[0]
        self.time = int(strs[1])
n,q = map(int, input().split(' '))
que = [Proc(input().split(' ')) for _ in range(n)]
proc_time = 0
while len(que) > 0:
    p = que.pop(0)
    if p.time <= q:
        proc_time += p.time
        print(p.name, proc_time)
    else:
        proc_time += q
        p.time -= q
        que.append(p)