問題文はこちら
テストインプットを0033.txtから開いているのでそのままでは通らない。
解答
def solve(balls): right, left = [0], [0] while balls: ball = balls.pop(0) if ball > right[-1]: right.append(ball) elif ball > left[-1]: left.append(ball) else: return "NO" return "YES" if __name__ == "__main__": data = open("./0033.txt").read().strip().split("\n")[1:] data = map(lambda x: map(int, x.split()), data) for balls in data: print solve(balls)