zogzog

Untitled

Jun 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import sys
  2.  
  3. ontrain = 0
  4. x = sys.stdin.readline()
  5. y = x.split()
  6. cap = int(y[0])
  7. b = int(y[1])
  8.  
  9. for i in range(0, b):
  10.   z = sys.stdin.readline()
  11.   g = z.split()
  12.   left = int(g[0])
  13.   enter = int(g[1])
  14.   stay = int(g[2])
  15.  
  16.   if left > ontrain:
  17.       print("impossible")
  18.       break
  19.  
  20.   if enter+ontrain > cap+1:
  21.       print("impossible")
  22.       break
  23.   else:
  24.       ontrain += enter
  25.       ontrain -= left
  26.      
  27.   space = cap-ontrain
  28.  
  29.   if i == b-1 and ontrain > 0:
  30.    print("impossible")
  31.    break
  32.   elif i == b-1 and stay > 0:
  33.     print("impossible")
  34.     break
  35.   elif stay > space+1:
  36.     print("impossible")
  37.     break
  38.   elif i == b-1:
  39.    print("possible")
  40.    break
Advertisement
Add Comment
Please, Sign In to add comment