Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Queue:
- def __init__(self,size=0):
- self.__data = []
- self.__size=size
- def push(self,element):
- self.__data.insert(0,element)
- def getFirst(self):
- return self.__data[-1]
- def getLast(self):
- return self.__data[0]
- def pop(self):
- return self.__data.pop()
- def isEmpty(self):
- return not len(self.__data)
- def qPrint(self):
- print(self.__data)
- def isFull(self):
- if self.__size!=0:
- return len(self.__data)>=self.__size
- else:
- return False
- class Package:
- def __init__(self, arrive,duration):
- self.__arrive=arrive
- self.__duration=duration
- def getArrive(self):
- return self.__arrive
- def getDuration(self):
- return self.__duration
- size,n=list(map(int,input().split()))
- buffer=Queue(size)
- abstime=0
- for i in range(n):
- inpack = Package(*list(map(int, input().split())))
- start=inpack.getArrive()
- duration=inpack.getDuration()
- if abstime < start and not buffer.isFull():
- abstime = start
- if not buffer.isFull():
- print(abstime)
- buffer.push(inpack)
- abstime += duration
- elif(buffer.getFirst().getDuration()-(start-buffer.getFirst().getArrive())<=0):
- buffer.pop()
- if abstime < start:
- abstime = start
- print(abstime)
- buffer.push(inpack)
- abstime += duration
- else:
- print(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement