avatar
hypnguyen

hypnguyen 1.8K 9th May, 2021

n, d = [int(i) for i in input().split(' ')]
x = []
h = []
result = 0
for i in range(n):
	a, b = [int (i) for i in input().split(' ')]
	x.append(a)
	h.append(b)

e = [0 for _ in range(max(x))]
for i in range(len(e)):
	for j in x:
		if i == j - 1:
			e[i] = h[x.index(j)]

def check(l):
	maxa = max(l)
	mina = min(l)
	if abs(l.index(mina) - l.index(maxa)) >= 3:
		if not maxa == mina:
			return True
	return False

for i in e:
	if i < 4:
		if check(e[i:i+4]):
			result += 1
	if i > 4:
		if check(e[i-4:i+4]):
			result +=1

print(result)
Python
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data