You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
635 B
Python
39 lines
635 B
Python
4 years ago
|
|
||
|
from collections import deque
|
||
|
|
||
|
|
||
|
p1 = deque()
|
||
|
p2 = deque()
|
||
|
|
||
|
|
||
|
with open('input', 'r') as f:
|
||
|
f.readline() # player 1
|
||
|
while (line := f.readline()) and line != '\n':
|
||
|
p1.append(int(line))
|
||
|
f.readline() # player 2
|
||
|
while (line := f.readline()) and line != '\n':
|
||
|
p2.append(int(line))
|
||
|
|
||
|
|
||
|
print(p1)
|
||
|
print(p2)
|
||
|
|
||
|
while len(p1) and len(p2):
|
||
|
a = p1.popleft()
|
||
|
b = p2.popleft()
|
||
|
winner = p1 if a > b else p2
|
||
|
winner.append(max(a, b))
|
||
|
winner.append(min(a, b))
|
||
|
|
||
|
print(p1)
|
||
|
print(p2)
|
||
|
|
||
|
winner = p1 if len(p1) else p2
|
||
|
i = 1
|
||
|
score = 0
|
||
|
while len(winner):
|
||
|
score += winner.pop() * i
|
||
|
i += 1
|
||
|
|
||
|
print(score)
|