n = int(input()) tony = input().split() tony2 = [] pom = 0 pom1 = 0 for i in range(n): tony[i] = int(tony[i]) tony2.append(tony[i]) wyzejnizej = True for i in range(1, n): if tony[i] >= tony[i-1] and wyzejnizej: pom += 1 tony[i] = -1000000 elif tony[i] <= tony[i-1] and wyzejnizej == False: pom += 1 tony[i] = 1000000 wyzejnizej = not wyzejnizej wyzejnizej = False for i in range(1, n): if tony2[i] >= tony2[i - 1] and wyzejnizej: pom1 += 1 tony2[i] = -1000000 elif tony2[i] <= tony2[i - 1] and wyzejnizej == False: pom1 += 1 tony2[i] = 1000000 wyzejnizej = not wyzejnizej if pom > pom1: print(pom1) else: print(pom)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | n = int(input()) tony = input().split() tony2 = [] pom = 0 pom1 = 0 for i in range(n): tony[i] = int(tony[i]) tony2.append(tony[i]) wyzejnizej = True for i in range(1, n): if tony[i] >= tony[i-1] and wyzejnizej: pom += 1 tony[i] = -1000000 elif tony[i] <= tony[i-1] and wyzejnizej == False: pom += 1 tony[i] = 1000000 wyzejnizej = not wyzejnizej wyzejnizej = False for i in range(1, n): if tony2[i] >= tony2[i - 1] and wyzejnizej: pom1 += 1 tony2[i] = -1000000 elif tony2[i] <= tony2[i - 1] and wyzejnizej == False: pom1 += 1 tony2[i] = 1000000 wyzejnizej = not wyzejnizej if pom > pom1: print(pom1) else: print(pom) |