Skip to content

Commit

Permalink
Add the Lineland problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyannn committed Jan 18, 2024
1 parent 525ec00 commit eb6c947
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lineland.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from math import inf


def main(cities):
def gen():
stack = [(-inf, -1)]
for i, v in enumerate(cities[::-1], -len(cities) + 1):
while stack[-1][0] >= v:
_ = stack.pop()
yield stack[-1][1]
stack.append((v, -i))

return list(gen())[::-1]


if __name__ == "__main__":
_ = input()
print(*main([int(s) for s in input().split()]))

0 comments on commit eb6c947

Please sign in to comment.