티스토리 뷰
modular 연산은 정말 최고야
bucket = [0]*3
amount = [0]*3
for i in range(3):
bucket[i], amount[i] = map(int, input().split())
for i in range(100):
howmany = min(amount[i%3], bucket[(i+1)%3]-amount[(i+1)%3])
amount[i%3] -= howmany
amount[(i+1)%3] += howmany
for a in amount:
print(a)
bucket = [0]*3
amount = [0]*3
for i in range(3):
bucket[i], amount[i] = map(int, input().split())
for i in range(100):
idx = i % 3
nxt = (idx+1) % 3
# 동시에 초기화 안해주면,
# amount[idx]의 변경된 값 기준으로 amount[nxt]가 계산된다!!
amount[idx], amount[nxt] = max(amount[idx] - (bucket[nxt] - amount[nxt]), 0), min(bucket[nxt], amount[nxt] + amount[idx])
for a in amount:
print(a)
'코딩테스트 > 백준' 카테고리의 다른 글
[BJ] 2493 탑 (0) | 2021.02.04 |
---|---|
[BJ] 17478. 재귀함수가뭔가요 (0) | 2021.02.01 |
[백준] 9037: The candy war (0) | 2020.11.15 |
[백준] 17224: APC는 왜 서브태스크 대회가 되었을까? (0) | 2020.11.15 |
[백준] 16165번: 걸그룹 마스터 준석이 (0) | 2020.11.15 |
댓글