You have a list of tasks, tasks[i] hours each, and you work in sessions of at most session_time hours. A task must be finished inside a single session (no splitting), you can do tasks in any order, and a session may hold several tasks as long as their total fits.
Write min_sessions(tasks: list[int], session_time: int) -> int returning the fewest sessions needed to finish every task.
Constraints: 1 <= len(tasks) <= 14, 1 <= tasks[i] <= session_time <= 15.
min_sessions([2, 3, 4], 5) # 2: {2, 3} and {4}
min_sessions([4, 4, 3, 3, 2], 8) # 2: {4, 4} and {3, 3, 2}
min_sessions([6, 6, 6], 6) # 3
Greedy packing (largest first into the first session with room) is not always optimal, and trying every assignment of tasks to sessions is too slow for 14 tasks. Aim for about O(2^n · n).
Show hint
With only 14 tasks, the set of tasks already finished fits in a bitmask. For each such set, it is enough to remember the best way to have finished it: the fewest sessions used, and among those, the least time used in the current session.