Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- 가상메모리 관리
- programmers
- 브루트포스
- 다익스트라
- 코딩테스트
- MYSQL
- 그리디
- 딕셔너리
- level3
- 재귀
- 구현
- level2
- python
- 스택
- BOJ
- N과M
- level1
- 운영체제
- 파이썬
- dict
- 수학
- dfs
- 프로그래머스
- 다이나믹 프로그래밍
- level0
- 백준
- BFS
- 힙
- DP
- 가상메모리
Archives
- Today
- Total
동캄의 코딩도장
백준 13305 [주유소] 파이썬 본문
https://www.acmicpc.net/problem/13305
13305번: 주유소
표준 입력으로 다음 정보가 주어진다. 첫 번째 줄에는 도시의 개수를 나타내는 정수 N(2 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 인접한 두 도시를 연결하는 도로의 길이가 제일 왼쪽 도로부터 N-1
www.acmicpc.net
n = int(input())
dis = list(map(int, input().split()))
city = list(map(int, input().split()))
city.pop()
i = 0
answer = 0
while i < len(dis):
j = 0
while (i+j+1) < len(dis) and city[i] <= city[i+j+1]:
j += 1
answer += sum(dis[i:i+j+1])*city[i]
i = i+j+1
print(answer)
간단한 그리디 문제이다.
cost가 작은 주유소가 나올때까지, cost* distance를 하여 더한다.
'코테 > BOJ' 카테고리의 다른 글
백준 1543 [문서 검색] 파이썬 (0) | 2022.02.11 |
---|---|
백준 11508 [2+1 세일] 파이썬 (0) | 2022.02.11 |
백준 2217 [로프] 파이썬 (0) | 2022.02.11 |
백준 16471 [작은 수 내기] 파이썬 (0) | 2022.02.11 |
백준 11256 [사탕] 파이썬 (0) | 2022.02.10 |