简单题,使 ∣S1−S2∣最小
1. 原文
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1and n2 numbers, respectively. Let S1 and S2 denote the sums of all the numbers in A1 and A2, respectively. You are supposed to make the partition so that ∣n1−n2∣ is minimized first, and then ∣S1−S2∣ is maximized.
Input Specification:
Each input file contains one test case. For each case, the first line gives an integer N (2≤N≤105), and then Npositive integers follow in the next line, separated by spaces. It is guaranteed that all the integers and their sum are less than 2^31.
output Specification:
For each case, print in a line two numbers: ∣n1−n2∣ and ∣S1−S2∣, separated by exactly one space.
Sample Input 1:
1 | 10 |
Sample output 1:
1 | 0 3611 |
Sample Input 1:
1 | 13 |
Sample output 1:
1 | 1 9359 |
2. 解析
|n1-n2|最小, |s1-s2|最大 :
数组递增排序,取前n/2部分和
3. AC代码
1 |
|