A1113. Integer Set Partition
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的更多相关文章
- PAT A1113 Integer Set Partition (25 分)——排序题
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- PAT甲级——A1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- A1113 | Integer Set Partition (25)
太简单了 #include <stdio.h> #include <memory.h> #include <math.h> #include <string& ...
- PAT_A1113#Integer Set Partition
Source: PAT A1113 Integer Set Partition (25 分) Description: Given a set of N (>) positive integer ...
- 1113 Integer Set Partition (25 分)
1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...
- PAT1113: Integer Set Partition
1113. Integer Set Partition (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...
- 1113. Integer Set Partition (25)
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- PAT 1113 Integer Set Partition
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
随机推荐
- input type=date时,时间数据回填,报错The specified value "2019-0404-18" does not conform to the required format, "yyyy-MM-dd".
<input autocomplete id="start-time" name="start_time" type="date" c ...
- SQL年月日格式化
Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
- Python 基础知识----数据类型
一.Number 类型(数值类型) 二.String 类型 (字符串类型) 三.List 类型 (列表类型) 是一种常用的序列类型簇,List 用中括号 [ ] 表示,不同的元素(任意类型的值)之间以 ...
- hive子查询
如果集合中含有空值,不能使用not in的语法指令:但是可以使用in
- Python魔法方法(magic method)细解几个常用魔法方法(下)
接上文,再介绍最后几个常用的魔法方法. 关于__dict__: 先上个例子: class Test(object): fly = True def __init__(self, age): self. ...
- DAY05、基本数据类型与内置方法
一.可变类型与不可变类型: 1.可变类型:值改变,但是id不变 2.不可变类型:值改变,id也改变 二.数据类型: 1.数字类型: 1.1:整型int: 用途:记录年龄.等级.数量 定义方式:age ...
- PHP爬虫框架Beanbun使用
第一 下载安装Beanbun框架 例如: mkdir -p BeanbunTest composer require kiddyu/beanbun 如图所示: 第二 简单下载网页的例子 <?ph ...
- scrapy 项目搭建
安装好scrapy后,开始创建项目 项目名:zhaopin 爬虫文件名:zhao 1:cmd -- scrapy startproject zhaopin 2:cd zhaopin,进入项目目 ...
- react 粗略使用
1.首先在index.html页面上写好dom,给他一个id让他引用js里的react. 2.index.js里面的代码就是三步走. 第一步:引用react,各种引用依赖. 第二步:创建dom,但它是 ...
- vue的 v-for 循环中图片加载路径问题
先看一下产品需求,如下图所示, 产品要求图片和它的名称一一对应,本来是非常简单的需求,后台直接返回图片路径和名称,前台直接读取就可以了,但是我们没有存储图片的服务器,再加上是一个实验性的需求,图片需要 ...