문제
-> 문제 링크 : https://www.algospot.com/judge/problem/read/LUNCHBOX
algospot.com :: LUNCHBOX
Microwaving Lunch Boxes 문제 정보 문제 After suffering from the deficit in summer camp, Ainu7 decided to supply lunch boxes instead of eating outside for Algospot.com winter camp. He contacted the famous packed lunch company "Doosot" to prepare N lun
www.algospot.com
문제풀이
이 문제에서 전자레인지로 도시락을 데우는 데 걸리는 시간은 정해져있다.
즉, 어떤 순서로 도시락을 배치하더라도 데우는 데 걸리는 시간을 줄일 수 없다.
그렇다면 남은 방법은 먹는 데 걸리는 시간을 이용해 도시락을 배치하는 것이다.
먹는 데 오래 걸리는 도시락을 먼저 데워서 빨리 먹기 시작하는 것이 전체 시간을 줄이는 합리적인 방법이라고 생각 할 수 있다.
코드
import sys
# 1개
T = int(sys.stdin.readline().rstrip())
for _ in range(T) :
N = int(sys.stdin.readline().rstrip())
warm = list(map(int,sys.stdin.readline().rstrip().split()))
eat = list(map(int,sys.stdin.readline().rstrip().split()))
lunch_boxes = sorted( zip(warm,eat), key = lambda x : (-x[1],x[0]) )
times = []
total_warm = 0
maxTime = 0
for idx, box in enumerate(lunch_boxes) :
total_warm += box[0]
maxTime = max(maxTime, total_warm + box[1])
print(maxTime)
코드에 잘못된 부분이나 개선 사항이 있다면 댓글로 알려주시면 감사하겠습니다.
'알고리즘 > 그리디' 카테고리의 다른 글
[python] algospot MINASTRITH 문제 풀이 (0) | 2020.07.07 |
---|---|
[python] algospot STRJOIN 문제풀이 (0) | 2020.07.05 |
[python] algospot MatchOrder 문제풀이 (0) | 2020.07.05 |