#abc374c. C - Separated Lunch

C - Separated Lunch

Score : 300300 points

问题陈述

随着基恩士总部的员工越来越多,他们决定将总部的部门分成两组,并错开他们的午餐时间。

基恩士总部有 NN 个部门,第 ii 个部门的人数为 KiK_i1iN1\leq i\leq N)。

在将每个部门分配到组 AA 或组 BB 时,让每个组同时进行午餐休息,并确保组 AA 和组 BB 的午餐休息时间不重叠,找到同时进行午餐休息的人数的最大可能值的最小值。 换句话说,找到以下两者中较大值的最小可能值:分配给组 AA 的部门的总人数,以及分配给组 BB 的部门的总人数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.

KEYENCE headquarters have NN departments, and the number of people in the ii-th department (1iN)(1\leq i\leq N) is KiK_i.

When assigning each department to Group AA or Group BB, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group AA and Group BB do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group AA, and the total number of people in departments assigned to Group BB.

Constraints

  • 2N202 \leq N \leq 20
  • 1Ki1081 \leq K_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

K1K_1 K2K_2 \ldots KNK_N

Output

Print the minimum possible value of the maximum number of people taking a lunch break at the same time.

Sample Input 1

5
2 3 5 10 12

Sample Output 1

17

When assigning departments 11, 22, and 55 to Group AA, and departments 33 and 44 to Group BB, Group AA has a total of 2+3+12=172+3+12=17 people, and Group BB has a total of 5+10=155+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 1717.

It is impossible to assign the departments so that both groups have 1616 or fewer people, so print 1717.

Sample Input 2

2
1 1

Sample Output 2

1

Multiple departments may have the same number of people.

Sample Input 3

6
22 25 26 45 22 31

Sample Output 3

89

For example, when assigning departments 11, 44, and 55 to Group AA, and departments 22, 33, and 66 to Group BB, the maximum number of people taking a lunch break at the same time is 8989.