if __name__ == "__main__": n: str = input() chain: str = input() chain: list = [int(x) for x in chain.split(" ")] result = 0 result2 = 0 for i in range(1, len(chain)-1, 2): if (chain[i] > chain[i-1]) or (chain[i] > chain[i+1]): chain[i] = min(chain[i-1], chain[i+1]) - 1 result +=1 elif (chain[i] < chain[i-1]) or (chain[i] < chain[i+1]): chain[i] = max(chain[i-1], chain[i+1]) + 1 result2 +=1 print(min(result, result2))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | if __name__ == "__main__": n: str = input() chain: str = input() chain: list = [int(x) for x in chain.split(" ")] result = 0 result2 = 0 for i in range(1, len(chain)-1, 2): if (chain[i] > chain[i-1]) or (chain[i] > chain[i+1]): chain[i] = min(chain[i-1], chain[i+1]) - 1 result +=1 elif (chain[i] < chain[i-1]) or (chain[i] < chain[i+1]): chain[i] = max(chain[i-1], chain[i+1]) + 1 result2 +=1 print(min(result, result2)) |