Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A​1​​ and A​2​​ of n​1​​and n​2​​ numbers, respectively. Let S​1​​ and S​2​​ denote the sums of all the numbers in A​1​​ and A​2​​, respectively. You are supposed to make the partition so that ∣ is minimized first, and then ∣ is maximized.

Input Specification:

Each input file contains one test case. For each case, the first line gives an integer N (2), 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: ∣ and ∣, separated by exactly one space.

Sample Input 1:

10
23 8 10 99 46 2333 46 1 666 555

Sample Output 1:

0 3611

Sample Input 2:

13
110 79 218 69 3721 100 29 135 2 6 13 5188 85

Sample Output 2:

1 9359

一句话,弱智题
 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, s1 = , s2 = , nMin, sMin;
int main()
{
cin >> n;
vector<int>v(n);
for (int i = ; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = ; i < n; ++i)
{
if (i < n / )
s1 += v[i];
else
s2 += v[i];
}
cout << n % << " " << s2 - s1 << endl;
return ;
}

最新文章

  1. disconf安装部署
  2. AfNetworking 3.0源码解读
  3. WPF之MVVM(Step1)&mdash;&mdash;自己实现ICommand接口
  4. 完全卸载Oracle方法、步骤
  5. messages.exe病毒的清理
  6. JS中的event 对象详解
  7. css3d
  8. 最大ASCII的和问题
  9. 也谈闭包--小白的JS进阶之路
  10. jdbc框架 commons-dbutils的使用
  11. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(5)
  12. Android(java)学习笔记162:Android启动过程(转载)
  13. codevs1009
  14. Objextive-C几道小题目笔记
  15. Windows中的对象
  16. MSDN官方XmlSerializer类导致内存泄漏和性能低
  17. javaScript 中String的常用方法
  18. js数组、内置对象、自定义对象
  19. Solidity constant view pure关键字的区别与联系
  20. 分析 js构造函数:对象方法 、类方法 、原型方法

热门文章

  1. Batch - call, start, goto 区别
  2. JAVA javah
  3. hive的数据压缩
  4. 51nod 1627 瞬间移动(组合数学)
  5. NOIp2018集训test-9-2(pm)
  6. (转)虚拟IP原理
  7. LeetCode 445. Add Two Numbers II (两数相加 II)
  8. 分布式存储glusterfs
  9. 本地 win7 与虚拟机Centos7 ping互通和Centos7 上网设置
  10. Spring AOP源码分析(三):基于JDK动态代理和CGLIB创建代理对象的实现原理