We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d838cb commit a58fe7dCopy full SHA for a58fe7d
YoonYn9915/greedy/2025-04-18-[백준]-#13305-주유소.py
@@ -0,0 +1,28 @@
1
+import sys
2
+
3
+inp = sys.stdin.readline
4
5
+n = int(inp())
6
7
+roads = list(map(int, inp().split()))
8
+oil_prices = list(map(int, inp().split()))
9
10
+# 최소 비용
11
+answer = 0
12
+# 현재 도시
13
+loc = 0
14
15
+while True:
16
+ # 현재 도시보다 기름값이 적은 곳 찾기
17
+ for i in range(loc + 1, n):
18
+ if oil_prices[loc] > oil_prices[i] or i == n - 1:
19
+ # 이곳까지 가기 위해 현재 도시에서 주유하면서 비용 소모
20
+ # 현재 도시의 기름값 * i번 도시까지 가야 할 거리
21
+ answer += oil_prices[loc] * sum(roads[loc:i])
22
+ loc = i
23
+ break
24
25
+ if loc == n - 1:
26
27
28
+print(answer)
0 commit comments