1113. Integer Set Partition (25)
来源:互联网 发布:centos broadcom 编辑:程序博客网 时间:2024/06/05 08:18
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and 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 N positive 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: |n1 - n2| and |S1 - S2|, separated by exactly one space.
Sample Input 1:1023 8 10 99 46 2333 46 1 666 555Sample Output 1:
0 3611Sample Input 2:
13110 79 218 69 3721 100 29 135 2 6 13 5188 85Sample Output 2:
1 9359
#include<iostream>#include<algorithm>using namespace std;int num[100005];int n;int main(){ int mid,sum1=0,sum2=0; cin>>n; for(int i=0;i<n;i++) cin>>num[i]; sort(num,num+n); mid=n/2; for (int i=0;i<mid;i++) sum1+=num[i]; for (int i=mid;i<n;i++) sum2+=num[i]; cout<<n%2<<" "<<sum2-sum1; return 0;}
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition
- 1113. Integer Set Partition
- PAT_A 1113. Integer Set Partition (25)
- pat 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25) PAT 甲级
- PAT 甲级 1113. Integer Set Partition (25)
- PAT--1113. Integer Set Partition
- windows下配置安装Anaconda+tensorflow
- 最小生成树(prime算法、kruskal算法) 和 最短路径算法(floyd、dijkstra)
- linux 下切换到root提示 Authentication failure的解决方法
- 继承、实现、依赖、关联、聚合、组合的联系与区别
- 机房收费系统(组合查询)
- 1113. Integer Set Partition (25)
- Java调用Mysql
- 2017年8月5日, 星期六
- 大话设计模式——六大原则(SOLID)
- [PAT乙级]1051. 复数乘法 (15)
- IOS CoreLocation中CLLocationManager类的基本使用
- 新书赠送中
- java邮件开发遇到no mimebodypart content
- 求第k大数