Problem:


Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

4 3
1 2 3 4
1 3
2 3
2 4

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

Sample Output 2

3



Sample input:
4 3
1 2 3 4
1 3
2 3
2 4


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
# C
N,M = map(int,input().split())
H = list(map(int,input().split()))
edge = [[0]]*N
for i in range(M):
    A,B = map(int,input().split())
    edge[A-1] = edge[A-1]+[H[B-1]]
    edge[B-1] = edge[B-1]+[H[A-1]]

count = 0
for i in range(N):
    if H[i] > max(edge[i]):
        count = count+1
    else:
        pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(' '))
H = list(map(int, input().split(' ')))
paths = [list(map(int, input().split(' '))) for _ in range(M)]
good_observatory = [True]*N
for i in range(N):
    for path in paths:
        if i == (path[0]-1) and H[i] <= H[path[1]-1]:
            good_observatory[i] = False
        elif i == (path[1]-1) and H[i] <= H[path[0]-1]:
            good_observatory[i] = False

print(sum(boolean for boolean in good_observatory))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [list(map(int, input().split())) for _ in range(m)]

# 隣接リスト
graph = [[] for _ in range(n)]
for v in p:
    graph[v[0]-1].append(v[1])
    graph[v[1] - 1].append(v[0])

cnt = 0
for x in graph:
    point = 'good'
    for y in x:
        if h[graph.index(x)] <= h[y-1]:
            point = 'bad'
    if point == 'good':
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain

n, m = map(int, input().split())
H = list(map(int, input().split()))

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

count = 0
skipset = []

for i in range(1, n+1):
    if i in skipset:
        continue
    f = {i}
    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c)) -f
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) < H[i-1]:
        #print(i, H[i - 1], max(e))
        skipset.append(d)
        count += 1
        #print('Yes')
    else:

        pass

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain

n, m = map(int, input().split())
H = list(map(int, input().split()))

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

count = 0

for i in range(1, n+1):
    f = {i}
    c= []
    e= []
    for j in ab:
        if i in j:
            c.append(j)
    d =set(chain.from_iterable(c)) -f
    #print(d)

    for k in d:
        e.append(H[k-1])



    if len(e)==0:
        count += 1
        #print('Yes')

        continue
    elif max(e) < H[i-1]:
        #print(i, H[i - 1], max(e))
        count += 1
        #print('Yes')
    else:
        pass

print(count)

Submission status: Time Limit Exceeded

Solution code:
(n, m), h, *r = [[*map(int, i.split())] for i in open(0)]
c = 0
for i in range(n):
    if i + 1 not in sum(r, []):
        c += 1
        continue
    l = [j * (i + 1 in j) for j in r]
    if h[i] > max(h[j-1] for j in set(sum(l, []))-{i + 1}):
        c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
#h = [[i, h[i-1]] for i in range(1, n+1)]
#path = [list(map(int, input().split())) for i in range(m)]
#conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))


for i in range(m):
    p = list(map(int, input().split()))
    # h0 > h1
    if h[p[0]-1] == h[p[1]-1]:
        if p[0] in tower:
            tower.remove(p[0])
        if p[1] in tower:
            tower.remove(p[1])
    elif h[p[0]-1] > h[p[1]-1]:
        if p[1] in tower:
            tower.remove(p[1])
    else:
        if p[0] in tower:
            tower.remove(p[0])

print(len(tower), end="")

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
#h = [[i, h[i-1]] for i in range(1, n+1)]
path = [list(map(int, input().split())) for i in range(m)]
#conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))


for p in path:
    # h0 > h1
    if h[p[0]-1] == h[p[1]-1]:
        if p[0] in tower:
            tower.remove(p[0])
        if p[1] in tower:
            tower.remove(p[1])
    elif h[p[0]-1] > h[p[1]-1]:
        if p[1] in tower:
            tower.remove(p[1])
    else:
        if p[0] in tower:
            tower.remove(p[0])

print(len(tower), end="")

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h = [[i, h[i-1]] for i in range(1, n+1)]
path = [list(map(int, input().split())) for i in range(m)]
conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))


for p in path:
    # h0 > h1
    if h[p[0]-1][1] == h[p[1]-1][1]:
        if p[0] in tower:
            tower.remove(p[0])
        if p[1] in tower:
            tower.remove(p[1])
    elif h[p[0]-1][1] > h[p[1]-1][1]:
        if p[1] in tower:
            tower.remove(p[1])
    else:
        if p[0] in tower:
            tower.remove(p[0])

"""
h.sort(key=lambda x: x[1], reverse=True)
for t in h:
    c = set(conn[t[0]])
    for i in c:
        if i in tower:
            tower.remove(i)
"""
print(len(tower), end="")

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
h = [[i, h[i-1]] for i in range(1, n+1)]
path = [list(map(int, input().split())) for i in range(m)]
conn = {key: [] for key in range(1, n+1)}
tower = list(range(1, n+1))


for p in path:
    # h0 > h1
    if h[p[0]-1][1] == h[p[1]-1][1]:
        conn[p[0]].append(p[1])
        conn[p[1]].append(p[0])
    elif h[p[0]-1][1] > h[p[1]-1][1]:
        conn[p[0]].append(p[1])
    else:
        conn[p[1]].append(p[0])

h.sort(key=lambda x: x[1], reverse=True)
for t in h:
    c = set(conn[t[0]])
    for i in c:
        if i in tower:
            tower.remove(i)
print(len(tower), end="")

Submission status: Time Limit Exceeded

Solution code:
import copy
n, m = map(int, input().split()) #n: 展望台の数, m: 道の数
height = list(map(int, input().split())) #高さリスト。nコある。
path = [list(map(int, input().split())) for _ in range(m)] #道リスト。
good_tower = 0 #解答

for i in range(n): #各展望台について.i+1の周辺をサーチ。
  h_i = height[i]
  con_num = [] #隣接する台番号を格納
  for j in range(m): #全pathをサーチ
    if i+1 in path[j]:
      p = copy.deepcopy(path[j])
      p.remove(i+1)
      c = p[0]
      con_num.append(c)
  if len(con_num) == 0:
    good_tower += 1
  else:
    con_num = list(set(con_num))
    cl = len(con_num)
    h_near_l = []
    for k in range(cl):
      t_num = con_num[k] #隣接台のナンバー
      h_near = height[t_num-1]
      h_near_l.append(h_near)
    if all(h_i > h_near_l[i] for i in range(cl)):
      good_tower += 1
      
print(good_tower)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n,m = map(int,input().split())
h = list(map(int,input().split()))

seen = np.array([[0 for i in range(n)] for j in range(n)])

for i in range(m):
  a,b = map(int,input().split())
  seen[a-1,b-1] = 1
  seen[b-1,a-1] = 1
  
ans = 0
for i in range(n):
  temp = np.multiply(seen[i],h)
  temp_1 = np.max(temp)
  if (h[i] > temp_1) and (temp_1 != 0):
    ans += 1
  elif temp_1 == 0:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
Input = input().split()
N = Input[0]
N = int(N)
M = Input[1]
M = int(M)

H = input().split()

Number = []
for x in range(N):
    Number.append(x+1)

for x in range(M):
    Input = input().split()
    A = Input[0]
    A = int(A)
    AH = H[A-1]
    B = Input[1]
    B = int(B)
    BH = H[B-1]
    if AH < BH:
        if A in Number:
           Number.remove(A)
    elif AH > BH:
        if B in Number:
            Number.remove(B)
    else:
        if A in Number:
            Number.remove(A)
        if B in Number:
            Number.remove(B)

print(len(Number))

Submission status: Time Limit Exceeded

Solution code:
#166-C（Peaks）

Input = input().split()
N = Input[0]
N = int(N)
M = Input[1]
M = int(M)

H = input().split()

Number = []

for x in range(N):
    Number.append(x+1)

for x in range(M):
    Input = input().split()
    A = Input[0]
    A = int(A)
    AH = H[A-1]
    B = Input[1]
    B = int(B)
    BH = H[B-1]
    if AH < BH:
        if A in Number:
           Number.remove(A)
    elif AH > BH:
        if B in Number:
            Number.remove(B)
    else:
        if A in Number:
            Number.remove(A)
        if B in Number:
            Number.remove(B)

print(len(Number))

Submission status: Time Limit Exceeded

Solution code:
Input = input().split()
N = Input[0]
N = int(N)
M = Input[1]
M = int(M)

H = input().split()

Number = []

for x in range(N):
    Number.append(x+1)

#Inputs = []
for x in range(M):
    Input = input().split()
    A = Input[0]
    A = int(A)
    AH = H[A-1]
    B = Input[1]
    B = int(B)
    BH = H[B-1]
    if AH < BH:
        if A in Number:
           Number.remove(A)
    elif AH > BH:
        if B in Number:
            Number.remove(B)
    else:
        if A in Number:
            Number.remove(A)
        if B in Number:
            Number.remove(B)

print(len(Number))
    #Inputs.append = Input

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [ list(map(int, input().split())) for _ in range(m) ]


d = [[ 0 for j in range(n)   ] for i in range(n) ]

for i in p:
    d[i[0]-1][i[1]-1] = h[i[1]-1]
    d[i[1]-1][i[0]-1] = h[i[0]-1]
c = [ 1 for i,v in enumerate(d) if max(v) < h[i] ]
print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
hight = list(input().split())
way =[]
A = [[0 for j in range(N)] for i in range(N)]
count = 0
flag = 0

for _ in range(M):
  a,b = map(int,input().split())
  A[a-1][b-1] = 1
  A[b-1][a-1] = 1

for x in range(N):
  if (1 in A[x]) == False:
      count+=1
  else:
    for y in range(N):
      if A[x][y] == 1:
        if hight[x] <= hight[y]:
          flag +=1
    if flag == 0:
      count +=1
    flag = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
tall = [int(e) for e in input().split()]
bridge = [[] for _ in range(n)]

for i in range(m):
    c = [int(f)-1 for f in input().split()]
    
    if tall[c[1]] not in bridge[c[0]]:
        bridge[c[0]].append(tall[c[1]])
    if tall[c[0]] not in bridge[c[1]]:
        bridge[c[1]].append(tall[c[0]])

cnt = 0
for j in range(n):
    if len(bridge[j]) == 0:
        cnt += 1
    elif tall[j] > max(bridge[j]):
        cnt += 1
    else:
        pass

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
height = list(map(int, input().split()))

roads = []
for i in range(m):
    x,y = map(int, input().split())
    roads.append([x-1,y-1])

bestcount = 0

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in range(m):
        if (roads[j][0] == i):
            a = roads[j][0]
            b = roads[j][1]
            if (height[a] <= height[b]):
                best = 0
                break
        if (roads[j][1] == i):
            a = roads[j][1]
            b = roads[j][0]
            if (height[a] <= height[b]):
                best = 0
                break
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
height = list(map(int, input().split()))

roads = []
for i in range(m):
    x,y = map(int, input().split())
    roads.append([x-1,y-1])

bestcount = 0

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in range(m):
        if (roads[j][0] == i):
            a = roads[j][0]
            b = roads[j][1]
            if (height[a] <= height[b]):
                best = 0
        if (roads[j][1] == i):
            a = roads[j][1]
            b = roads[j][0]
            if (height[a] <= height[b]):
                best = 0
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.extend(list(map(int,input().split())))
ans=N
for n in range(1,N+1):
    for m in range(0,M*2,2):
        if(pathlist[m]==n):#自身じゃない方の灯台
            if(high_list[n-1]<=high_list[pathlist[m+1]-1]):#経路先が自身よりも高い
                ans=ans-1#回答に含まない
                break
        elif(pathlist[m+1]==n):
            if(high_list[n-1]<=high_list[pathlist[m]-1]):#経路先が自身よりも高い
                ans=ans-1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n,m = nm()
h = nl()
path = [[False]*n for _ in range(n)]

for i in range(n):
    path[i][i] = True 

for i in range(m):
    a,b = nm()
    path[a-1][b-1] = path[b-1][a-1] = True

res = 0
for i,j in enumerate(path):
    temp = []
    for k,l in enumerate(j):
        if l:
            temp.append(h[k])
    ma = max(temp)
    if temp.count(ma) == 1 and  ma == h[i]:
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=[0]*N
ans=N
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            if(m[0]==n):#自身じゃない方の灯台
                if(high_list[n-1]<=high_list[m[1]-1]):#経路先が自身よりも高い
                    ans=ans-1#回答に含まない
                    break
            else:
                if(high_list[n-1]<=high_list[m[0]-1]):#経路先が自身よりも高い
                    ans=ans-1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy  as np
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=np.array([[0]*N]*N)
#i行目にi番目から行ける展望台をすべて入れる
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            if(m[0]==n):#自身じゃない方の高さを代入
                waylist[n-1][m[1]-1]=high_list[m[1]-1]
            else:
                waylist[n-1][m[0]-1]=high_list[m[0]-1]

answer=0
for n in range(N):
    if(waylist[n].max()<high_list[n]):
        answer=answer+1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
h_input = list(map(int,input().split()))
A = [0]*m
B = [0]*m
for i in range(m):
    A[i],B[i] = map(int,input().split())

ans=0
for i in range(n):
    h1 = h_input[i]
    h2 = 0
    flag = True
    for j in range(m):
        if A[j]-1==i:
            h2 = h_input[B[j]-1]
        if B[j]-1==i:
            h2 = h_input[A[j]-1]
        if h2>=h1:
            flag=False
            break
    if flag:
        ans+=1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split(' '))
H=list(map(int,input().split(' ')))

data=[]
for n1 in range(N):
  data.append([])
  for n2 in range(N):
    data[n1].append(0)
    
for m in range(M):
  a,b=map(int,input().split(' '))
  data[a-1][b-1]=H[b-1]
  data[b-1][a-1]=H[a-1]
ans=0
for n in range(N):
  if H[n-1]>max(data[n-1]):
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().strip().split()]
height = [None] + [int(i) for i in input().strip().split()]
graph = [[] for _ in height]
result = 0
his = []
for _ in range(m):
    i, j = [int(i) for i in input().strip().split()]
    if j not in graph[i]:
        graph[i].append(j)
    if i not in graph[j]:
        graph[j].append(i)

for i in range(1, len(height)):
    if i in his:
      continue
      
    peak = True
    for j in graph[i]:
        if height[i] <= height[j]:
            peak = False
            break
    if peak:
        his.extend(graph[i])
        result += 1
        
print(result)

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().strip().split()]
height = [None] + [int(i) for i in input().strip().split()]
graph = [[] for _ in height]
result = 0
for _ in range(m):
    i, j = [int(i) for i in input().strip().split()]
    if j not in graph[i]:
        graph[i].append(j)
    if i not in graph[j]:
        graph[j].append(i)

for i in range(1, len(height)):
    peak = True
    for j in graph[i]:
        if height[i] <= height[j]:
            peak = False
            break
    if peak:
        result += 1
        
print(result)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
H = list(map(int,input().split()))

list = list(range(1,n+1))
for _ in range(m):
  a,b=map(int,input().split())
  if H[a-1] > H[b-1] and b in list:
    list.remove(b)
  elif H[a-1] < H[b-1] and a in list:
    list.remove(a)
  elif H[a-1] == H[b-1]:
    if a in list and b in list:
      list.remove(a)
      list.remove(b)
    elif a in list:
      list.remove(a)
    elif b in list:
      list.remove(b)
print(len(list))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []

good = []
no_good = []

for i in range(M):
    t = list(map(int, input().split()))
    A.append(t[0])
    B.append(t[1])

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        g = A[i]
        n = B[i]
    elif H[A[i]-1] < H[B[i]-1]:
        g = B[i]
        n = A[i]
    else:
        no_good.append(A[i])
        no_good.append(B[i])
        continue

    if (g not in no_good) and (g not in good):
        good.append(g)
    if n in good:
        good.remove(n)
    no_good.append(n)

used = set(A) | set(B)
good_num = len(good)
unused_num = N - len(used)
result = good_num + unused_num
print(result)

Submission status: Time Limit Exceeded

Solution code:
n,m =map(int,input().split())
h=list(map(int,input().split()))
result=list(range(n))
for i in range(m):
    a,b =map(int,input().split())
    a-=1
    b-=1
    if h[a]>h[b]:
        if b in result:
            x=result.pop(result.index(b))
    elif h[a]<h[b]:
        if a in result:
            x=result.pop(result.index(a))
    else:
        if a in result:
            x=result.pop(result.index(a))
        if b in result:
            x=result.pop(result.index(b))

print(len(result))

Submission status: Time Limit Exceeded

Solution code:

n,m = map(int, input().split())
h_a = list(map(int, input().split()))

m_l = [[0,0]]*m
for i in range(m):
  m_l[i] = list(map(int, input().split()))

cnt = 0
for ni in range(n):
  t = h_a[ni]
  for r in m_l:
    com = -1;
    if r[0] - 1 == ni:
      com = h_a[r[1] - 1]
    elif r[1] - 1 == ni:
      com = h_a[r[0] - 1]
    if com >= t:
      t = float('inf')
      break

  if t==h_a[ni]:
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main() :
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    LEFT  = 0
    RIGHT = 1
    pairs = []

    for itr in range(M) :
        pairs.append(list(map(int, input().split())))

    
    resurt = 0
    for itr in range(N) :
        checkl = []
        for inner_itr in range(N) :
            checkl.append(False)
        
        count = 1
        for inner_itr in range(M) :
            if pairs[inner_itr][LEFT] == (itr + 1) :
                if H[itr] <= H[pairs[inner_itr][RIGHT] - 1] :
                    count = 0
                    break
                checkl[RIGHT - 1] = True                    

            if pairs[inner_itr][RIGHT] == (itr + 1) :
                if H[itr] <= H[pairs[inner_itr][LEFT] - 1] :
                    count = 0
                    break
                checkl[LEFT - 1] = True
        resurt += count
        checkl = None
    
    print(resurt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main() :
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    LEFT  = 0
    RIGHT = 1
    pairs = []

    for itr in range(M) :
        pairs.append(list(map(int, input().split())))

    
    resurt = 0
    for itr in range(N) :
        checkl = []
        for inner_itr in range(N) :
            checkl.append(False)
        
        count = 1
        for inner_itr in range(M) :
            if pairs[inner_itr][LEFT] == (itr + 1) :
                if H[itr] <= H[pairs[inner_itr][RIGHT] - 1] :
                    count = 0
                    break
                elif H[itr] == H[pairs[inner_itr][RIGHT] - 1] :
                    if checkl[RIGHT - 1] == False :
                        count += 1
                        checkl[RIGHT - 1] = True                    

            if pairs[inner_itr][RIGHT] == (itr + 1) :
                if H[itr] <= H[pairs[inner_itr][LEFT] - 1] :
                    count = 0
                    break
                elif H[itr] == H[pairs[inner_itr][LEFT] - 1] :
                    if checkl[LEFT - 1] == False :
                        count += 1
                        checkl[LEFT - 1] = True
        resurt += count
        checkl = None
    
    print(resurt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
l = sys.stdin.readline().strip()
N, M = map(int, l.split())
link = []
for i in range(N+1):
    link.append([-1] * (N+1))

l = sys.stdin.readline().strip()
heights = [-1] + list(map(int, l.split()))

for i in range(M):
    l = sys.stdin.readline().strip()
    A, B = map(int, l.split())
    if A!= B:
        link[A][B] = 1
        link[B][A] = 1

count = 0
impossible = set()
for i in range(1, N+1):
    if i in impossible:
        continue
    hs = []
    his = []
    for j in range(1, N+1):
        if link[i][j] == 1:
            hs.append(heights[j])
            his.append(j)
    if hs ==[]:
        count += 1
        continue

    if heights[i] > max(hs):
        count += 1
        for one in his:
            impossible.add(one)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]   
result = 0

for i in range(n):
    cnt = 0
    j = i + 1
    x = []
    for a, b in ab:
        if j == a:
            x.append(b)
        elif j == b:
            x.append(a)
    for y in x:
        if h[i] > h[y-1]:
            cnt += 1
        elif h[i] <= h[y-1]:
            break
    if cnt == len(x):
        result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

def main():
    observs, bridges = map( int, input().split() )
    heights = list( map( int, input().split() ) )
    btable = [ 0 for _ in range(observs * observs) ]

    for _ in range(bridges):
        fr, to = map( int, input().split() )
        btable[ (fr - 1) * observs + (to - 1) ] = 1
        btable[ (to - 1) * observs + (fr - 1) ] = 1
    
    count = 0
    for i in range(observs):
        higher = True
        for j in range(observs):
            if i == j or btable[ i * observs + j ] == 0:
                continue
            if btable[ i * observs + j ] == btable[ j * observs + i ]:
                if heights[i] <= heights[j]:
                    higher = False
        if higher:
            count += 1
    
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
n,m = map(int,input().split())
h = [int(x) for x in input().split()]
p = []
for i in range(m):
    p.append([int(x) for x in input().split()])
h2 = copy.copy(h)
p2 = copy.copy(p)
g = []
for i in range(len(h)):
    j = i + 1
    c = False
    for pt in p2:
        if not (j in pt):
            continue
        gp = copy.copy(pt)
        lh = h[gp.pop(pt.index(j)) - 1]
        rh = h[gp.pop() - 1]
        if lh <= rh:
            c = True
            break
    if not c:
        g.append(j)
print(len(g))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())

H_t = input()

H = [0]*N
ma = []*N

good_count = 0

for i in range(N):
    
    H[i]= int(H_t.split()[i])
    ma.append(0)

#print(H_M)

for j in range(M):
    a, b = map(int, input().split())
    
    ma[a-1] = max(ma[a-1], H[b-1]) # つながった展望台の中で一番高い展望台を保持する
    ma[b-1] = max(ma[b-1], H[a-1]) 
    
    
for i in range(N):
    if H[i] > ma[i]:
        good_count +=1
print(good_count)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
H=list(map(int,input().split()))
List=[list(map(int,input().split())) for i in range(M)]
ans=0
alllist=[[0 for i in range(N)]for j in range(N)]

for j in range(M):
    alllist[List[j][0]-1][List[j][1]-1]=1
    alllist[List[j][1]-1][List[j][0]-1]=1


for s in range(N):
    flag=True
    for t in range(N):
        if H[s]>alllist[s][t]*H[t]:
            a=1
        else:
            flag=False   
            break
    if flag:
        ans=ans+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]   
result = 0

for i in range(n):
    cnt = 0
    j = i + 1
    x = []
    for a, b in ab:
        if j == a:
            x.append(b)
        elif j == b:
            x.append(a)
    for y in x:
        if h[i] > h[y-1]:
            cnt += 1
    if cnt == len(x):
        result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h = list(map(int, input().split()))
bad = []
ans =[]

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1] > h[b-1]:
        bad.append(b)
    elif h[a-1] == h[b-1]:
        bad.append(a)
        bad.append(b)
    else:
        bad.append(a)

j = 1
for j in range(n+1):
    if j in bad:
        pass
    else:
        ans.append(j)
    j += 1
        
print(len(ans)-1)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
h = list(map(int, input().split()))
good = []
bad = []
ans =[]

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1] > h[b-1]:
        good.append(a)
        bad.append(b)
    elif h[a-1] == h[b-1]:
        bad.append(a)
        bad.append(b)
    else:
        good.append(b)
        bad.append(a)

j = 1
for j in range(n+1):
    if j in bad:
        pass
    else:
        ans.append(j)
    j += 1
        

print(len(ans)-1)

Submission status: Time Limit Exceeded

Solution code:
array=[]
road=[]

inpt=input()
N,M=inpt.split()
N=int(N)
M=int(M)
inpt=input()
array=inpt.split()
for n in range(N):
    array[n]=int(array[n])
for m in range(M):
    inpt=input()
    road+=[inpt.split()]

count=0
for n in range(N):

    for m in range(M):
        mark=0
        flag=1

        if str(n+1) in road[m][0] or str(n+1) in road[m][1]:
            if array[n]>array[int(road[m][1])-1] or array[n]>array[int(road[m][0])-1]:
                flag=1
            else:
                flag=0
                break
        else:mark+=1

    if flag==1:
        count+=1
    if mark==M:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
for i in range(m):
    ai, bi = map(int, input().split())
    ab.append([ai-1,bi-1])

v = [True]*n
for i in range(m):
    for j in range(n):
        if ab[i][0] == j or ab[i][1] == j:
            if h[ab[i][0]] > h[ab[i][1]]:
                v[ab[i][1]] = False
            elif h[ab[i][0]] < h[ab[i][1]]:
                v[ab[i][0]]= False
            else:
                v[ab[i][0]]= False
                v[ab[i][1]]= False

print(v.count(True))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
H = [0]*N
H = list(map(int, input().split()))
Roads = [list(map(int, input().split())) for i in range(M)]
FP = [0]*N

for i in range(1,N+1):
  Opp = []
  t = 0
  if FP[i-1] == 0:
    for j in range(M):
      if i in Roads[j]:
        if i == Roads[j][0]:
          Opp.append(Roads[j][1])
        else:
          Opp.append(Roads[j][0])
    
    if len(Opp) == 0:
      FP[i-1] = 1
      continue
    
    for j in Opp:
      if H[j-1] < H[i-1]:
        FP[j-1] = -1
        t += (-FP[j-1])
    
    if t == len(Opp):
      FP[i-1] = 1

print(FP.count(1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

good_ob = []
for i in range(N):
    good_ob.append(i+1)

for i in range(M):
    if H[road[i][0]-1] > H[road[i][1]-1]:
        if road[i][1] in good_ob:
            good_ob.remove(road[i][1])
    elif H[road[i][0]-1] < H[road[i][1]-1]:
        if road[i][0] in good_ob:
            good_ob.remove(road[i][0])
    else:
        if road[i][1] in good_ob:
            good_ob.remove(road[i][1])
        if road[i][0] in good_ob:
            good_ob.remove(road[i][0])


print(len(good_ob))