Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class Queue:
  2. def __init__(self,size=0):
  3. self.__data = []
  4. self.__size=size
  5. def push(self,element):
  6. self.__data.insert(0,element)
  7. def getFirst(self):
  8. return self.__data[-1]
  9. def getLast(self):
  10. return self.__data[0]
  11. def pop(self):
  12. return self.__data.pop()
  13. def isEmpty(self):
  14. return not len(self.__data)
  15. def qPrint(self):
  16. print(self.__data)
  17. def isFull(self):
  18. if self.__size!=0:
  19. return len(self.__data)>=self.__size
  20. else:
  21. return False
  22. class Package:
  23. def __init__(self, arrive,duration):
  24. self.__arrive=arrive
  25. self.__duration=duration
  26. def getArrive(self):
  27. return self.__arrive
  28. def getDuration(self):
  29. return self.__duration
  30. size,n=list(map(int,input().split()))
  31. buffer=Queue(size)
  32. abstime=0
  33. for i in range(n):
  34. inpack = Package(*list(map(int, input().split())))
  35.  
  36. start=inpack.getArrive()
  37. duration=inpack.getDuration()
  38. if abstime < start and not buffer.isFull():
  39. abstime = start
  40. if not buffer.isFull():
  41. print(abstime)
  42. buffer.push(inpack)
  43. abstime += duration
  44. elif(buffer.getFirst().getDuration()-(start-buffer.getFirst().getArrive())<=0):
  45. buffer.pop()
  46. if abstime < start:
  47. abstime = start
  48. print(abstime)
  49. buffer.push(inpack)
  50. abstime += duration
  51. else:
  52. print(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement