Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created April 13, 2024 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/3c7057d09bef1bb70fd52d2c56c3ba4e to your computer and use it in GitHub Desktop.
Save maehrm/3c7057d09bef1bb70fd52d2c56c3ba4e to your computer and use it in GitHub Desktop.
INF = 10**10
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [INF] * N # dp[i]:町iの上流をたどって見たとき、金1kgを買える最安値
G = [[] for _ in range(N)]
for _ in range(M):
x, y = map(lambda n: int(n) - 1, input().split())
G[x].append(y)
for i in range(N):
for j in G[i]:
dp[j] = min(dp[i], dp[j], A[i])
ans = -INF
for i in range(N):
ans = max(ans, A[i] - dp[i])
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment