From c822e22243fd96516ec37a300c40d29351cae252 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Sun, 20 Sep 2026 14:32:58 +0900 Subject: [PATCH] 1665 --- ... Minimum Initial Energy to Finish Tasks.py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/1665. Minimum Initial Energy to Finish Tasks.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1665. Minimum Initial Energy to Finish Tasks.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1665. Minimum Initial Energy to Finish Tasks.py" new file mode 100644 index 000000000..be95b0c38 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1665. Minimum Initial Energy to Finish Tasks.py" @@ -0,0 +1,18 @@ +''' +1. 아이디어: +actual이 최소이고, minimum이 최대인 것일 수록 먼저 수행해야한다. +2. 시간복잡도: +o(nlogn) +3. 알고리즘: +정렬 후, 순회하면서 energy를 계산한다. +''' +class Solution: + def minimumEffort(self, tasks: list[list[int]]) -> int: + tasks = sorted(tasks, key=lambda x: x[1] - x[0]) + print(tasks) + + energy = 0 + for actual, minimum in tasks: + energy = max(minimum, actual + energy) + + return energy \ No newline at end of file