본문 바로가기

Algorithm/Greedy

[Python] 백준 11399번 : ATM (S3) - 그리디단계별3

#문제

www.acmicpc.net/problem/11399

 

11399번: ATM

첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)

www.acmicpc.net

#풀이 & 학습한 내용

"기다리는 시간의 합을 최소화하는 문제"입니다. 소요되는 시간이 적을수록 앞에 배치해야 하므로 시간기준 오름차순으로 정렬해주고, 순서대로 합을 구해주면 됩니다.

 

#소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
= int(input())
total_wait = 0 #각 손님마다 걸리는 시간의 총합
 
waits = list(map(int,input().split()))
waits.sort() #걸리는 시간 오름차순정렬
#print(waits)
 
now_sum = 0 #현재 손님 앞까지 더해진 시간
 
for wait in waits:
  now_sum+=wait
  total_wait+=now_sum
 
print(total_wait)
cs

 

github.com/HoYoungChun/Algorithm_PS/blob/master/Greedy/BOJ_11399.py

 

HoYoungChun/Algorithm_PS

Baekjoon Online Judge, Programmers problem solving by Python, C++ - HoYoungChun/Algorithm_PS

github.com