반응형
https://www.acmicpc.net/problem/20055
삼성 기출이라그런지 좀 까다로웠다.
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
nums = list(map(int, input().split()))
up = 0
down = n-1
count = 0
zero = 0
robots = [False for _ in range(2*n)]
while True:
count += 1
up -= 1
down -= 1
if up < 0:
up += 2*n
if down < 0:
down += 2*n
if robots[down]:
robots[down] = False
if up < down:
end = up
else:
end = up-2*n
for i in range(down-1, end, -1):
if robots[i] and not robots[i+1] and nums[i+1] >= 1:
robots[i] = False
robots[i+1] = True
nums[i+1] -= 1
if nums[i+1] == 0:
zero += 1
if (i+1) == down:
robots[i+1] = False
if nums[up] != 0:
robots[up] = True
nums[up] -= 1
if nums[up] == 0:
zero += 1
if zero >= k:
break
print(count)
댓글