Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def push(stack, way1):
- '''
- Переместить 1 вагон с 1-го пути в
- '''
- stack.append(way1.pop())
- def pull(way2, stack):
- '''
- Переместить 1 вагон из тупика на 2-й путь
- '''
- way2.append(stack.pop())
- def push_train(stack, way1, cnt=0):
- '''
- Переместить вагоны в тупик пока следующий вагон по номеру меньше предыдущего
- или если тупик пуст
- '''
- if not way1:
- return 0
- elif not stack or stack[-1] >= way1[-1]:
- push(stack, way1)
- cnt += push_train(stack, way1, cnt)
- return cnt + 1
- elif stack[-1] < way1[-1]:
- return 0
- n = int(input())
- way1 = [int(x) for x in input().split()]
- way1.reverse()
- stack = []
- print(push_train(stack, way1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement