====== The Milk Queue ====== ===== 풀이 ===== * [[ps:problems:boj:5910]] 동일한 문제. 풀이는 그쪽을 참고. 덤으로, [[ps:problems:boj:7744]]도 동일한 문제. ===== 코드 ===== """Solution code for "BOJ 14778. The Milk Queue". - Problem link: https://www.acmicpc.net/problem/14778 - Solution link: http://www.teferi.net/ps/problems/boj/14778 Tags: [greedy] """ import sys import functools def main(): N = int(sys.stdin.readline()) A_and_B = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)] A_and_B.sort( key=functools.cmp_to_key( lambda x, y: ( (x[0] - x[1]) - (y[0] - y[1]) if (comp := min(x[0], y[1]) - min(x[1], y[0])) == 0 else comp ) ) ) first_barn_time = second_barn_time = 0 for a, b in A_and_B: first_barn_time += a second_barn_time = max(second_barn_time, first_barn_time) + b print(second_barn_time) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:플래티넘_4}}