Algorithm/acmicpc.net
실버는 선녀야 (#13305 주유소)
winney916
2024. 10. 15. 13:10
728x90
#13305 주유소 https://www.acmicpc.net/problem/13305
어제 기하학 플래티넘 문제를 풀고 멘탈이 나가있던 상황에서, 오늘은 이 문제를 풀게됐다.
그냥 쉬웠다.
그리디 알고리즘인 만큼 논리적으로 최적해를 찾아내면 된다.
n = int(input())
distance = [int(x) for x in input().split()]
oil_cost = [int(x) for x in input().split()]
answer = 0
i = 0
while i < n:
now = oil_cost[i]
for j in range(i + 1, n):
next = oil_cost[j]
if next < now:
break
else: # 현재 위치보다 작은게 없는 경우
answer += now * sum(distance[i:])
break
next = j
answer += sum(distance[i:j]) * now
i = j
print(answer)