#C7535. Optimal Task Distribution
Optimal Task Distribution
Optimal Task Distribution
You are given a list of integer tasks where each task is represented by its processing time. The goal is to distribute these tasks between two machines such that the maximum load (i.e. the sum of task times assigned to one machine) is minimized.
Mathematically, if you have a list \(a_1, a_2, \ldots, a_n\), you need to partition it into two subsets \(S\) and \(\bar{S}\) such that the value \[ \min \max\Bigl(\sum_{i \in S} a_i, \; \sum_{i \notin S} a_i\Bigr) \] is achieved. In the special case where there are no tasks (i.e. an empty list), the answer is 0.
inputFormat
Input is provided via standard input. The first line contains a single integer \(n\) representing the number of tasks. If \(n > 0\), the second line contains \(n\) space-separated integers representing the processing times of the tasks. If \(n = 0\), no second line is given.
outputFormat
Print a single integer representing the minimized maximum workload after optimally distributing the tasks between two machines using standard output.
## sample5
2 3 5 8 2
10