Algorithm&CodingTest/Baekjoon
[Baekjoon] [13305] 실버3 - 주유소 Python
kitez
2024. 1. 29. 18:35
주유소
13305번: 주유소
표준 입력으로 다음 정보가 주어진다. 첫 번째 줄에는 도시의 개수를 나타내는 정수 N(2 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 인접한 두 도시를 연결하는 도로의 길이가 제일 왼쪽 도로부터 N-1
www.acmicpc.net
내 코드
from sys import stdin
N = int(stdin.readline())
kmList = list(map(int, stdin.readline().split()))
oilList = list(map(int, stdin.readline().split()))
pay = 0
curIdx = 0
while True:
# print(curIdx)
if curIdx >= len(oilList)-1:
break
# 현재 주유소에서 나보다 주유소 가격이 싼경우 전까지 다 사야함
nextIdx = curIdx + 1
for idx in range(curIdx +1, len(oilList)):
if idx == len(oilList) - 1:
nextIdx = idx
if oilList[idx] < oilList[curIdx]:
nextIdx = idx
break
# print("nextId", nextIdx)
# 구매한 km oil 계산
for idx in range(curIdx, nextIdx):
pay += oilList[curIdx] * kmList[idx]
curIdx = nextIdx
# print("pay", pay)
# print()
print(pay)
728x90