[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ / Python
๐ Problem Solving/Programmers
import sys
input = sys.stdin.readline
bridge_length, weight = map(int, input().split())
truck_weights = list(map(int, input().split()))
def solution(bridge_length, weight, truck_weights):
bridge = [0] * bridge_length
time = 0
while bridge:
time += 1
bridge.pop(0)
if truck_weights:
if sum(bridge) + truck_weights[0] <= weight:
bridge.append(truck_weights.pop(0))
else:
bridge.append(0)
return time
print(solution(bridge_length, weight, truck_weights))
ํด์ค
๋ค๋ฆฌ ๊ธธ์ด๋งํผ 0์ผ๋ก ์ด๊ธฐํ ๋ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ ๋ค. 1์ด๊ฐ ์ง๋ ๋๋ง๋ค ๋ฆฌ์คํธ์ ๋งจ ์ ๊ฐ์ ๋นผ์ค๋ค. ์ด ํ, ๋ฆฌ์คํธ์ truck_weights์ ์ฒซ ๋ฒ์งธ ๊ฐ์ ํฉ์ด weight๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๋, truck_weight์ ์ฒซ ๋ฒ์งธ ๊ฐ์ ๋ฆฌ์คํธ์ ๋ฃ์ด์ค๋ค. ๋ง์ฝ ์กฐ๊ฑด์ ๋ง์ง ์๋๋ค๋ฉด 0์ ๋ฃ์ด์ค๋ค.
'๐ Problem Solving > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํฐ ์ ๋ง๋ค๊ธฐ / Python (0) | 2021.06.14 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] H-index / Python (0) | 2021.06.14 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์์ฅ / Python (0) | 2021.06.14 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์นดํซ / Python (0) | 2021.06.14 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๊ฐ์ฅ ํฐ ์ / Python (0) | 2021.06.14 |