Created
April 13, 2024 01:54
-
-
Save maehrm/3c7057d09bef1bb70fd52d2c56c3ba4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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