Skip to content

Commit

Permalink
20241219 (#9009)
Browse files Browse the repository at this point in the history
  • Loading branch information
humwawe authored Dec 20, 2024
1 parent 07f3db2 commit 913a48e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions daily_problems/2024/12/1219/personal_submission/cf1056c_hum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
n, m = map(int, input().split())
powers = [0] + list(map(int, input().split()))

prs = [0] * (2 * n + 1)
for _ in range(m):
x, y = map(int, input().split())
prs[x] = y
prs[y] = x

used = [0] * (2 * n + 1)

t = int(input())
last = 0

for _ in range(n):
if t == 2:
last = int(input())
used[last] = 1

if last and prs[last] and not used[prs[last]]:
print(prs[last], flush=True)
used[prs[last]] = 1
else:
v, chosen = -1, 0
for i in range(1, 2 * n + 1):
if prs[i] and not used[i] and powers[i] - powers[prs[i]] > v:
v = powers[i] - powers[prs[i]]
chosen = i

if not chosen:
for i in range(1, 2 * n + 1):
if not used[i] and powers[i] > v:
v = powers[i]
chosen = i

print(chosen, flush=True)
used[chosen] = 1

if t == 1:
last = int(input())
used[last] = 1

0 comments on commit 913a48e

Please sign in to comment.