fork download
  1. s, n = map(int,input().split())
  2. coll = []
  3. for i in range(n):
  4. x, y = map(int,input().split())
  5. coll.append([x,y,0])
  6.  
  7. coll = sorted(coll,key=lambda x:x[1])
  8.  
  9. found = 1
  10. kills = 0
  11.  
  12. while(found):
  13. found = 0
  14. for i in range(n-1,-1,-1):
  15. if coll[i][0]<s and coll[i][2] is 0:
  16. if coll[i][1] is 0:
  17. s -= coll[i][0]
  18. else:
  19. s += coll[i][1]
  20. coll[i][2] = 1
  21. kills+=1
  22. found = 1
  23. break
  24.  
  25. if kills is n:
  26. print ('YES')
  27. else:
  28. print ('NO')
Runtime error #stdin #stdout #stderr 0.02s 28384KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
EOFError: EOF when reading a line