Advertisement
Bad_Programist

Untitled

Feb 3rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. a, n = list(map(int, input().split()))
  2. score = list(map(int, input().split()))
  3. A = []
  4. Maxscore = [0 for i in range(a)]
  5. for i in range(n):
  6.     A.append(list(map(int, input().split())))
  7.  
  8. Maxscore[0] = score[0]  
  9. for i in range(1, a):
  10.     Ch = []
  11.     for j in A:
  12.         if j[1] == i + 1:
  13.             Ch.append(Maxscore[j[0] - 1])
  14.     if Ch == []:
  15.         Maxscore[i] = score[i]
  16.     else:
  17.         Maxscore[i] = max(max(Ch), 0) + score[i]
  18. print(max(Maxscore))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement