728x90
반응형
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
Python
import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
total = 0
ans = 0
for x in arr:
#print(ans,ans+x)
ans = ans+x
total += ans
print(total)
풀이
입력 예제
5
3 1 4 3 2
그 때 ans와 ans+x의 변화
ans | ans+x |
0 | 1 |
1 | 3 |
3 | 6 |
6 | 9 |
9 | 13 |
total = 32
728x90
반응형
'Algorithm Problems' 카테고리의 다른 글
[백준] [Python] 3190번 뱀 - 큐, Greedy (0) | 2021.06.05 |
---|---|
[백준] [Python] 13305번 주유소 - Greedy (0) | 2021.06.01 |
[백준] [Python] 6198번 옥상 정원 꾸미기 - 스택 (0) | 2021.06.01 |
[백준] [Python] 1158번 요세푸스 문제 - 큐 (0) | 2021.05.30 |
[백준] [Python] 5430번 AC - 스택 (0) | 2021.05.29 |