#C10575. Minimizing Workday Duration Difference
Minimizing Workday Duration Difference
Minimizing Workday Duration Difference
Given a list of task durations, your goal is to partition the tasks into two workdays such that the absolute difference between the total durations of the two workdays is minimized.
Let \( T = [t_1, t_2, \dots, t_n] \) be the list of task durations. You need to divide these tasks into two groups so that the value
\[ \Delta = \left| \sum_{i=1}^{n} t_i - 2\times S \right| \]is minimized, where \( S \) is the sum of one workday. In other words, you must optimize the partition to balance the workload.
inputFormat
The first line of input is an integer \( n \) indicating the number of tasks.
The second line contains \( n \) space-separated integers, where each integer represents the duration of a task.
outputFormat
Output a single integer representing the minimal absolute difference between the total durations of the two workdays after an optimal partition of the tasks.
## sample5
2 3 7 4 1
1
</p>