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
- BOJ
- 이것이코딩테스트다
- 개발자북클럽
- 빅데이터분석
- 다이나믹프로그래밍
- 정렬
- 프로그래머스
- 타입스크립트
- react-native
- bfs
- TS
- 노마드코더
- 이진탐색
- ps
- 코딩테스트
- Typescript
- 백준
- 앱개발
- 코테
- c++
- 알고리즘
- 코딩일기
- dfs
- 구현
- 최단경로
- 이코테
- SQL
- DP
- 백준온라인저지
- 그리디
Archives
- Today
- Total
한량처럼 살고 싶다
1859. 백만 장자 프로젝트(Python) 본문
https://swexpertacademy.com/main/code/problem/problemDetail.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
뒤에서부터 가격을 체크해야하는 것이 포인트이다.
def solution(T):
for i in range(T):
length = int(input())
arr = list(map(int, input().split()))
answer = 0 #최종 금액
price = 0 #내가 소비한 가격
count = 0 #내가 산 개수
biggest_price = arr[length-1]
for index in range(length-2, -1, -1):
if arr[index] < biggest_price:
count += 1 #구매 개수
price -= arr[index] #소비 금액
else:
earn = biggest_price * count
earn += price
answer += earn
biggest_price = arr[index]
count = 0
price = 0
if count:
answer += ((biggest_price*count)+price)
print("#%d %d" %(i+1, answer))
T= int(input())
solution(T)
'PS > SWEA' 카테고리의 다른 글
[SWEA] 파리 퇴치 (python) (0) | 2024.02.02 |
---|---|
[SWEA] 창용 마을 무리의 개수 (python) (0) | 2024.01.13 |
1206. [S/W 문제해결 기본] 1일차 - View(Python) (0) | 2023.10.19 |
2072. 홀수만 더하기(Python) (0) | 2023.10.19 |