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. Angular MVC

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...

  2. git修改用户名、邮箱

    在windows使用git命令方法如下(以win7为例):1.msysgit 是 Windows 版的 Git可以百度搜索Git下载.2.安装完成后,开始菜单里找到“Git”->“Git Bas ...

  3. com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class cn.edu.

    详细信息   https://www.cnblogs.com/xuwenjin/p/8832522.html 解决办法: 在实体类上面加上注解 @JsonIgnoreProperties(value ...

  4. Json dump

    json 模块提供了一种很简单的方式来编码和解码JSON数据. 其中两个主要的函数是 json.dumps() 和 json.loads() , 要比其他序列化函数库如pickle的接口少得多. 下面 ...

  5. python之路--内置模块02

    一. namedtuple 命名元组->类似创建了一个类 from collections import namedtuple # 类 p = namedtuple("Point&qu ...

  6. k8s容器的资源限制

    1.k8s支持内存和cpu的限制 requests:容器运行需求,最低保障limits:限制,硬限制(资源上限) CPU: 1颗逻辑CPU(1核CPU=4个逻辑CPU) 1物理核=1000个微核(mi ...

  7. JQ判断在不同分辨率电脑下使用不同的banner尺寸

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 莫烦keras学习自修第一天【keras的安装】

    1. 安装步骤 (1)确保已经安装了python2或者python3 (2)安装numpy,python2使用pip2 install numpy, python3则使用pip3 install nu ...

  9. Delphi窗体之间互相调用的简单问题

    问题是这样的,我的程序主窗口Form1上面有一个数据连接(ADOCONNECTION1)和ADOQUERY,然后还有一些数据感知组件用于浏览用的,我打算点击From1中的一个“修改数据”按钮,就弹出F ...

  10. css瀏覽器私有前綴名

    -webkit-:chrome,safari -o-:opera -moz-:firefox -ms-:ie