PAT甲级——A1113 Integer Set Partition
2024-09-06 06:58:16
Given a set of N (>) 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 ∣ 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 231.
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 ;
}
最新文章
- disconf安装部署
- AfNetworking 3.0源码解读
- WPF之MVVM(Step1)&mdash;&mdash;自己实现ICommand接口
- 完全卸载Oracle方法、步骤
- messages.exe病毒的清理
- JS中的event 对象详解
- css3d
- 最大ASCII的和问题
- 也谈闭包--小白的JS进阶之路
- jdbc框架 commons-dbutils的使用
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(5)
- Android(java)学习笔记162:Android启动过程(转载)
- codevs1009
- Objextive-C几道小题目笔记
- Windows中的对象
- MSDN官方XmlSerializer类导致内存泄漏和性能低
- javaScript 中String的常用方法
- js数组、内置对象、自定义对象
- Solidity constant view pure关键字的区别与联系
- 分析 js构造函数:对象方法 、类方法 、原型方法