Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a, n = list(map(int, input().split()))
- score = list(map(int, input().split()))
- A = []
- Maxscore = [0 for i in range(a)]
- for i in range(n):
- A.append(list(map(int, input().split())))
- Maxscore[0] = score[0]
- for i in range(1, a):
- Ch = []
- for j in A:
- if j[1] == i + 1:
- Ch.append(Maxscore[j[0] - 1])
- if Ch == []:
- Maxscore[i] = score[i]
- else:
- Maxscore[i] = max(max(Ch), 0) + score[i]
- print(max(Maxscore))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement