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: Wrong Answer

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


class MyQueue:
    def __init__(self, size):
        self.queue = [0 for i in range(size)]
        self.max_size = size
        self.head = 0
        self.tail = 0

    def initialize(self):
        self.head = self.tail = 0

    def is_empty(self):
        if self.head == self.tail:
            return True
        return False

    def is_full(self):
        if self.head == (self.tail + 1) % self.max_size:
            return True
        return False

    def enqueue(self, elm):
        if self.is_full():
            raise Exception
        self.queue[self.tail] = elm
        if self.tail + 1 == self.max_size:
            self.tail = 0
        else:
            self.tail += 1
        return self.queue

    def dequeue(self):
        if self.is_empty():
            raise Exception
        x = self.queue[self.head]
        if self.head + 1 == self.max_size:
            self.head = 0
        else:
            self.head += 1
        return x


def main(queue, n):
    total = 0
    while queue.head != queue.tail:
        q = queue.dequeue()
        process = q[0]
        time = int(q[1])
        time = time - n
        if 0 > time:
            tmp = 100 + time
            total += tmp
            print(process + " " + str(total))
        else:
            total += 100
            queue.enqueue((process, str(time)))


n, q = [int(s) for s in input().split()]
queue = MyQueue(n+1)
for i in range(n):
    name, time = input().split()
    queue.enqueue((name, time))
main(queue, q)

Submission status: Wrong Answer

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


class MyQueue:
    def __init__(self, size):
        self.queue = [0 for i in range(size)]
        self.max_size = size
        self.head = 0
        self.tail = 0

    def initialize(self):
        self.head = self.tail = 0

    def is_empty(self):
        if self.head == self.tail:
            return True
        return False

    def is_full(self):
        if self.head == (self.tail + 1) % self.max_size:
            return True
        return False

    def enqueue(self, elm):
        if self.is_full():
            raise Exception
        self.queue[self.tail] = elm
        if self.tail + 1 == self.max_size:
            self.tail = 0
        else:
            self.tail += 1
        return self.queue

    def dequeue(self):
        if self.is_empty():
            raise Exception
        x = self.queue[self.head]
        if self.head + 1 == self.max_size:
            self.head = 0
        else:
            self.head += 1
        return x


def main(queue, n):
    total = 0
    while queue.head != queue.tail:
        q = queue.dequeue()
        process = q[0]
        time = int(q[1])
        time = time - n
        if 0 > time:
            tmp = 100 + time
            total += tmp
            print(process, total)
        else:
            total += 100
            queue.enqueue((process, str(time)))


if __name__ == '__main__':
    n, q = [int(s) for s in input().split()]
    queue = MyQueue(n+1)
    for i in range(n):
        name, time = input().split()
        queue.enqueue((name, time))
    main(queue, q)

Submission status: Wrong Answer

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


class MyQueue:
    def __init__(self, size):
        self.queue = [0 for i in range(size)]
        self.max_size = size
        self.head = 0
        self.tail = 0

    def initialize(self):
        self.head = self.tail = 0

    def is_empty(self):
        if self.head == self.tail:
            return True
        return False

    def is_full(self):
        if self.head == (self.tail + 1) % self.max_size:
            return True
        return False

    def enqueue(self, elm):
        if self.is_full():
            pass
        self.queue[self.tail] = elm
        if self.tail + 1 == self.max_size:
            self.tail = 0
        else:
            self.tail += 1
        return self.queue

    def dequeue(self):
        if self.is_empty():
            raise Exception
        x = self.queue[self.head]
        if self.head + 1 == self.max_size:
            self.head = 0
        else:
            self.head += 1
        return x


def main(queue, n):
    total = 0
    while queue.head != queue.tail:
        q = queue.dequeue()
        process = q[0]
        time = int(q[1])
        time = time - n
        if 0 > time:
            tmp = 100 + time
            total += tmp
            print(process, total)
        else:
            total += 100
            queue.enqueue((process, str(time)))


if __name__ == '__main__':
    n, q = [int(s) for s in input().split()]
    queue = MyQueue(10000)
    for i in range(n):
        name, time = input().split()
        queue.enqueue((name, time))
    main(queue, q)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
name = []
time = []
endtime =[]
endname = []
for i in range(n):
    a = input().split()
    name.append(a[0])
    time.append(int(a[1]))
s = 0
while True:
    if time[0]> 100:
        time[0] -= 100
        time.append(time.pop(0))
        name.append(name.pop(0))
        s += 100
    else:
        s += time[0] 
        time.pop(0)
        print(name.pop(0),s)      
    
    if len(name) == 0:
        break

Submission status: Wrong Answer

Solution code:
def initialize():
    global head, tail


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


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


def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1


def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t


if __name__ == "__main__":
    n, q = map(int, input().split())
    head = 0
    tail = n
    MAX = 100000
    Q = [0]*MAX
    runtime = 0
    for i in range(n):
        name, time = input().split()
        Q[i] = ([name, int(time)])
    while head != tail:
        t_list = dequeue()
        if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime))
    print(Q)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
l = [list(input().split()) for i in range(n)]
from collections import deque
que = deque([[l[i][0], int(l[i][1])] for i in range(n)])
a = []
time = 0
while que != deque([]):
    a = que.popleft()
    if a[1] <= 100:
        time += a[1]
        print("{} {}".format(a[0], str(time)))
    else:
        time += 100
        a[0], a[1] = a[0], a[1] - 100
        que.append(a)

Submission status: Wrong Answer

Solution code:
import collections
import sys

n,q = map(int,input().split())
data = [[i for i in input().split()]for i in range(n)]
time = 0
while data:
    task = data[0]
    del data[0]
    if int(task[1]) < q:
        time += int(task[1])
        print(task[0],time)
      
    else:
        time += q
        task[1] = str(int(task[1]) - q)
        data.append(task)

Submission status: Wrong Answer

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

p = []
time = 0

for i in range(n):
	p.append(input().split())
	p[i][1] = int(p[i][1])

print("{0} {1}".format(p[0][0], time))

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

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
label = [0 for i in range(n)]
content = [0 for i in range(n)]
for i in range(n):
    label[i], content[i] = input().split()
    content[i] = int(content[i])
time = 0
count = 0

while True:
    for i in range(n):
        if content[i] == 0:
            i += 1
        elif 0 < content[i] <= q:
            time += content[i]
            content[i] = 0
            print("p"+str(i+1)+" "+str(time))
            count += 1
        else:
            time += q
            content[i] = content[i] - q
    if count == n:
        break

Submission status: Wrong Answer

Solution code:
s = raw_input().split()
n = int(s[0])
q = int(s[1])

process_name = []
process_time = []
for x in xrange(n):
  ps = raw_input().split()
  process_name.append(ps[0])
  process_time.append(int(ps[1]))

total_time = 0
while process_name != []:
  pn = process_name.pop(0)
  pt = process_time.pop(0)
  if pt <= q:
    total_time += pt
    print pn, total_time
  else: 
    total_time += q
    process_name.append(pn)
    process_time.append(pt-q)

print total_time

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
queuekey = []
queuetime = []

for i in range(0, a[0]):
    tmp = list(input().split())
    queuekey.append(tmp[0])
    queuetime.append(int(tmp[1]))

spentTime = 0
while len(queuetime) > 0:
    if queuetime[0] < a[1]:
        spentTime += queuetime[0]
        print(queuekey[0], end="")
        print(' ', end="")
        print(spentTime)
        queuekey.pop(0)
        queuetime.pop(0)
    else:
        spentTime += a[1]
        queuetime[0] -= a[1]
        queuetime.append(queuetime[0])
        queuekey.append(queuekey[0])
        queuetime.pop(0)
        queuekey.pop(0)

Submission status: Wrong Answer

Solution code:
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
    Q.append(input().split())
t=0
res=[]
while Q!=[]:
    if int(Q[0][1])<q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
    del Q[0]
for i in res:
    print(i[0]+" "+str(i[1]))

Submission status: Wrong Answer

Solution code:
class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= 100
        tmp = self.delete()
        self.el.append(tmp)

n, q = map(int, raw_input().split())
qu = Queue()

for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    qu.add({'name':name, 'time':time})

time = 0
while qu.el:
    #print qu.el
    if qu.el[0]['time'] > q:
        qu.action()
        time += q
    else:
        time += qu.el[0]['time']
        print qu.el[0]['name'], time
        qu.delete()

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().strip().split())

A = []
D = {}
for l in range(N):
    n, t = input().strip().split()
    D[n] = int(t)
    A.append(n)

print(A)
T = 0
d = 0
while True:
    n = A.pop(0)
    if D[n] > Q:
        D[n] -= Q
        T += Q
        A.append(n)
    else:
        T += D[n]
        print('{0} {1}'.format(n, T))
        d += 1
        if d == N:
            break

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().strip().split())

A = []
D = {}
for l in range(N):
    n, t = input().strip().split()
    D[n] = int(t)
    A.append(n)

print(A)
T = 0
d = 0
while True:
    n = A.pop(0)
    if D[n] > Q:
        D[n] -= Q
        T += Q
        A.append(n)
    else:
        T += D[n]
        print('{0}  {1}'.format(n, T))
        d += 1
        if d == N:
            break

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().strip().split())

A = []
D = {}
for l in range(N):
    n, t = input().strip().split()
    D[n] = int(t)
    A.append(n)

print(A)
T = 0
d = 0
while True:
    n = A.pop(0)
    if D[n] > Q:
        D[n] -= Q
        T += Q
        A.append(n)
    else:
        T += D[n]
        print(str(n) + ' ' + str(T))
        d += 1
        if d == N:
            break

Submission status: Wrong Answer

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

processes = []

for i in range(int(n)):
    process_name, process_time = input().split()
    processes.append([process_name, int(process_time)])

elapsed_time = 0
while len(processes):
    process = processes.pop(0)
    if process[1] > 100:
        process[1] -= 100
        processes.append(process)
        elapsed_time += 100
    else:
        elapsed_time += process[1]
        print(process[0], elapsed_time)

Submission status: Wrong Answer

Solution code:
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(len(queue) != 0):
    item = queue.pop()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

Submission status: Wrong Answer

Solution code:
class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

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


def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    print('done')

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

def round_robin_scheduling(N, Q, A):
    time = 0
    finished_process = []
    while A:
        process = A.popleft()
        if process[1] < Q:
            time += process[1]
            finished_process.append([process[0],time])
        else:
            time += Q
            A.append([process[0],process[1]-Q])
    else:
        return finished_process

if __name__ == '__main__':
    N,Q = map(int,input().split())
    # a = [input().split() for i in range(N)]
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    answer = round_robin_scheduling(N,Q,A) 
    for x in answer:
        print (x[0], x[1])

Submission status: Wrong Answer

Solution code:
from collections import deque

def round_robin_scheduling(N, Q, A):
    time = 0
    while A:
        process = A.popleft()
        if process[1] < Q:
            time += process[1]
            print(process[0],time) 
        else:
            time += Q
            A.append([process[0],process[1]-Q])

if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A)

Submission status: Wrong Answer

Solution code:
from collections import deque

def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] < Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q])

if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
from collections import deque

def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] < Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q])

if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A)

Submission status: Wrong Answer

Solution code:
import queue
procs = queue.Queue()

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

for i in range(n):
    name,time = input().split()
    procs.put((name,int(time)))
time=0
doneprocs = queue.Queue()
while True:
    if procs.empty():
        break
    temp = procs.get()
    if temp[1] < q:
        time += temp[1]
        doneprocs.put((temp[0],time))
    else:
        time+= q
        procs.put((temp[0],temp[1]-q))
for i in range(n):
    temp = doneprocs.get()
    print(temp[0],temp[1])

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict

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

for i in range(n):
    name, time = input().split()
    od.update({name: int(time)})
total = 0

while len(od) > 0:
    name, time = od.popitem(False)
    if time < q:
        total += time
        print("{} {}".format(name, total))
    else:
        total += q
        time -= q
        od.update({name: time})

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print('{0} {1}'.format(r.name, r.time))


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time < time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    process_count, process_time, processes = get_input()
    result =  run_roundrobin(processes = processes, time = process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time = 0, result=[]):
    if not processes:
        return result

    p = processes.popleft()
    if p.time < time:
        total_time += p.time
        p.time = total_time
        result.append(p)
    else:
        total_time += time
        p.time -= time
        processes.append(p)

    return run_roundrobin(processes, time, total_time, result)



def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    process_count, process_time, processes = get_input()
    result = run_roundrobin(processes=processes, time=process_time)
    for r in result:
        print(r.name, r.time)


def run_roundrobin(processes, time, total_time=0, result=[]):
    while not processes:
        p = processes.popleft()
        if p.time <= time:
            total_time += p.time
            p.time = total_time
            result.append(p)
        else:
            total_time += time
            p.time -= time
            processes.append(p)

    return result


def get_input():
    count, time = list(map(lambda x: int(x), input().split(' ')))

    processes = deque([])
    for _ in range(count):
        im = input().split(' ')
        p = Process(im[0], int(im[1]))
        processes.append(p)

    return count, time, processes


class Process():

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


main()

Submission status: Wrong Answer

Solution code:

import collections
#データの入力
a=input().split()

number=int(a[0])
quantum=int(a[1])

#保持データの作成
time=0

#キューの作成
name=[]
name=collections.deque()
q=[]
q=collections.deque()

#結果の保持
result=[[0 for i in range(2)]for j in range(number)]
endednumber=0

totaltime=0

for i in range(number):
    b=input().split()
    name.append(b[0])
    q.append(int(b[1]))
    totaltime+=int(b[1])

#キューの処理
while totaltime>time:
    cn=name.popleft()
    cq=q.popleft()

    if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        print("ended",time,result)
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)
        print("continue",name,q)

#結果の表示
for i in range(number):
    print(result[i][0],result[i][1])

Submission status: Wrong Answer

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

queue = [input().split() for y in range(n)]
time = 0;

print(queue[1:] + queue[:1])
while True:
    if int(queue[0][1]) <= 100:
        time += int(queue[0][1])
        print(queue[0][0], time)
        if len(queue) == 1:
            break
        queue.pop(0)
    else:
        time += 100
        queue[0][1] = str(int(queue[0][1]) - 100)
        queue = queue[1:] + queue[:1]

Submission status: Wrong Answer

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

queue = [input().split() for y in range(n)]
time = 0;

while True:
    if int(queue[0][1]) <= 100:
        time += int(queue[0][1])
        print(queue[0][0], time)
        if len(queue) == 1:
            break
        queue.pop(0)
    else:
        time += 100
        queue[0][1] = str(int(queue[0][1]) - 100)
        queue = queue[1:] + queue[:1]

Submission status: Wrong Answer

Solution code:
from collections import deque

n,q=[int(i) for i in input().split()]
name=[0 for i in range(n)]
time=[0 for i in range(n)]
answer_name=[]
answer_time=[]
total_time=0

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

d_name = deque(name)
d_time = deque(time)

while len(d_name)>0:

    a=d_name.popleft()
    b=int(d_time.popleft())

    if b>100:
        d_name.append(a)
        d_time.append(b-100)
        total_time=total_time+100

    else:
        total_time=total_time+b
        answer_name.append(a)
        answer_time.append(total_time)

for i in range(len(answer_time)):
    print(answer_name[i], answer_time[i])

Submission status: Wrong Answer

Solution code:
#operand.py using polish way of expressing
data = input()
operators = "+-*/"
command = data.split()

operand = []  #used to store operand"s"
for com in command:
    if com in operators: #do some calculation on the last one and the second last one XD
        second = operand.pop()
        first = operand.pop()

        if com == '+':
            out = first + second
        elif com == "-":
            out = first - second
        elif com == "*":
            out = first * second
        elif com == "/":
            out = first / second
        operand.append(out)
        out = int() #clear out
    else:  #store operand into to buffer
        operand.append(int(com))

print(operand[0])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
p=[]
for _ in[0]*n:
 s,k=input().split()
 p+=[[s,int(k)]]
b=list(range(n))
t=0
while sum(b):
 for i in b:
  a=p[i]
  if a[1]>q:a[1]-=q;t+=q
  else:b.remove(i);t+=a[1];print(a[0],t)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t,a=0,[]
while d:
 k,v=d.popleft()
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;a+=(k,t)
print(*a,sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t,a=0,[]
while d:
 k,v=d.popleft()
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;a+=[(k,t)]
print(*a,sep='\n')

Submission status: Wrong Answer

Solution code:
import queue
q = queue.Queue()
exetime = 0

n, quantum = map(int, input().split())
for i in range(n):
    q.put(tuple(input().split())) # tupleで渡す

while not q.empty():
    process = q.get()
    #print(process)
    time = int(process[1])
    if time > 100:
        exetime += 100
        q.put((process[0], time - 100))
    else:
        exetime += time
        print(process[0], exetime)

Submission status: Wrong Answer

Solution code:
s=0
A=input().split()
n=(int)(A[0])
t=(int)(A[1])
x=[0 for i in range(2*n)]
for i in range(n):
    B=input().split()
    k=2*i
    x[k]=(B[0])
    x[k+1]=(int)(B[1])
while len(x)>0:
    s=x[1]-t
    if s>0: 
        sum=t
        x.append(x[0])
        x.append(s)
        del x[0]
        del x[0]
    if s<=0:
        sum+=x[1]
        print( x[0],":",sum)
        del x[0]
        del x[0]

Submission status: Wrong Answer

Solution code:
s=0
A=input().split()
n=(int)(A[0])
t=(int)(A[1])
x=[0 for i in range(2*n)]
for i in range(n):
    B=input().split()
    k=2*i
    x[k]=(B[0])
    x[k+1]=(int)(B[1])
while len(x)>0:
    s=x[1]-t
    if s>0: 
        sum=t
        x.append(x[0])
        x.append(s)
        del x[0]
        del x[0]
    if s<=0:
        sum+=x[1]
        print( x[0],sum)
        del x[0]
        del x[0]

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(f(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}\n']
 print(a[:-1])
m()

Submission status: Wrong Answer

Solution code:
#16D8101014F 久留米 竜之介 Python

n,time=map(int,input().split())
timenow = 0
p=[]
q=[]
queue=[] #p1,p2....
Queue=[] #time
for i in range (n):
	line=input().split()
	q.append(int(line.pop()))
	p.append(line.pop())

head=0
tail=len(p)-1
while head is not tail:
	#print(p)
	#print(q)
	#print(head,tail)
	Ptmp=q[head]
	if Ptmp<=100:
		timenow+=Ptmp
		queue.append(p[head])
		Queue.append(timenow)
		head+=1
	else:
		timenow+=100
		Ptmp-=100
		q.append(Ptmp)
		p.append(p[head])
		head+=1
		tail+=1
Ptmp=q[head]
timenow+=Ptmp
queue.append(p[head])
Queue.append(timenow)

for i in range(n):
		print(queue[i],Queue[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
i=0
remain = n
while True:
    if time[i] == 0:
        i += 1
        if i == n:
            i = 0
        continue
    if time[i] <= q:
        finished.append(name[i])
        time[i] = 0
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        i += 1
        if i == n:
            i = 0

print_array(finished)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] == 0:
        i += 1
        if i == n:
            i = 0
        continue
    if time[i] <= q:
        current_time += time[i]
        finished.append(name[i])
        fin_time.append(current_time)
        time[i] = 0
        remain -= 1
        if remain == 0:
            break
    else:
        time[i] -= q
        current_time += q
        i += 1
        if i == n:
            i = 0

for i in range(n):
    print("{} {}".format(name[i], fin_time[i]))