주유소
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
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] [21921] 실버3 - 블로그 Python (1) | 2024.01.31 |
---|---|
[Baekjoon] [20920] 실버3 영단어 암기는 괴로워 Python (0) | 2024.01.29 |
[Baekjoon] [2164] 실버4 - 카드2 Python (0) | 2024.01.29 |
[Baekjoon] [17266] 실버4 - 어두운 굴다리 Python (1) | 2024.01.29 |
[Baekjoon] [9017] 실버3 - 크로스 컨트리 Python (0) | 2024.01.24 |