Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2numbers, 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:

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<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int num[], N;
int main(){
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%d", &num[i]);
}
sort(num, num + N);
int mid = N / ;
int sum1 = , sum2 = ;
for(int i = mid; i < N; i++){
sum2 += num[i];
}
for(int i = mid - ; i >= ; i--){
sum1 += num[i];
}
if(N % == )
printf("%d %d", , sum2 - sum1);
else printf("%d %d", , sum2 - sum1);
cin >> N;
return ;
}

A1113. Integer Set Partition的更多相关文章

  1. PAT A1113 Integer Set Partition (25 分)——排序题

    Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...

  2. PAT甲级——A1113 Integer Set Partition

    Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...

  3. A1113 | Integer Set Partition (25)

    太简单了 #include <stdio.h> #include <memory.h> #include <math.h> #include <string& ...

  4. PAT_A1113#Integer Set Partition

    Source: PAT A1113 Integer Set Partition (25 分) Description: Given a set of N (>) positive integer ...

  5. 1113 Integer Set Partition (25 分)

    1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...

  6. PAT1113: Integer Set Partition

    1113. Integer Set Partition (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  7. PAT 甲级 1113 Integer Set Partition

    https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...

  8. 1113. Integer Set Partition (25)

    Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...

  9. PAT 1113 Integer Set Partition

    Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...

随机推荐

  1. mybatis数据源与连接池

    1.概念介绍1.1 数据源:顾名思义,数据的来源,它包含了数据库类型信息,位置和数据等信息,一个数据源对应一个数据库. 1.2 连接池:在做持久化操作时,需要通过数据库连接对象来连接数据库,而连接池就 ...

  2. 搭建ELK日志分析系统

    看了辣么多博客,就数这个最详细最容易理解了:https://blog.csdn.net/qq_22211217/article/details/80764568 >>>>> ...

  3. k8s使用glusterfs做存储

    一.安装glusterfs https://www.cnblogs.com/zhangb8042/p/7801181.html 环境介绍; centos 7 [root@k8s-m ~]# cat / ...

  4. prometheus和metrucs-server (k8s监控)

    资源指标:metrucs-server 自定义指标:prometheus, k8s-prometheus-adapter(转换prometheus数据的格式) 新一代架构: 核心指标流水线:由kube ...

  5. adoquery怎样判断数据在缓存中有修改啊

    ADOQry.Filtered:=false;       ADOQry.Filtered:=true;       ADOQry.FilterGroup:=fgPendingRecords ;Fil ...

  6. C#中decimal,double和float的区别

    float 单精度浮点 32bit,double 双精度浮点64bit,decimal是高精度 128bit,浮点型.float double 是 基本类型(primitive type),decim ...

  7. Lodop打印控件不打印css背景图怎么办

    background:url()这是css背景图,http协议会按异步方式下载背景图,所以很容易等不到下载完毕就开始打印了,故lodop不打印css背景图.Lodop不打印css背景图,但是有其他方法 ...

  8. Siki的虚幻第一季

    空项目.一闪而过的解决方法 命名空间std::cout的作用: int ,long , long long类型的范围 unsigned   int   0-4294967295 int   21474 ...

  9. UOJ272 [清华集训2016] 石家庄的工人阶级队伍比较坚强 【分治乘法】

    题目分析: 首先不难注意到式子就是异或卷积,所以考虑用分治乘法推出优化方法.我们把一个整体$f$拆成$f-,f\pm,f+$,然后另一个拆成$g-,g\pm,g+$.这样做的好处是能更清楚的分析问题. ...

  10. 洛谷P3690 Link Cut Tree (模板)

    Link Cut Tree 刚开始写了个指针版..调了一天然后放弃了.. 最后还是学了黄学长的板子!! #include <bits/stdc++.h> #define INF 0x3f3 ...