Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A​1​​ and A​2​​ of n​1​​and n​2​​ numbers, respectively. Let S​1​​ and S​2​​ denote the sums of all the numbers in A​1​​ and A​2​​, 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 2​31​​.

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 ;
}

PAT甲级——A1113 Integer Set Partition的更多相关文章

  1. PAT 甲级 1113 Integer Set Partition

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

  2. PAT甲级1103. Integer Factorization

    PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...

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

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

  4. A1113. Integer Set Partition

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

  5. PAT甲级——1103 Integer Factorization (DFS)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90574720 1103 Integer Factorizatio ...

  6. A1113 | Integer Set Partition (25)

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

  7. PAT甲级——A1103 Integer Factorization

    The K−P factorization of a positive integer N is to write N as the sum of the P-th power of Kpositiv ...

  8. PAT甲级1103 Integer Factorization【dfs】【剪枝】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805364711604224 题意: 给定一个数n,要求从1~n中找 ...

  9. PAT_A1113#Integer Set Partition

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

随机推荐

  1. spark-sql中的分析函数的使用

    分析函数的应用场景: (1)用于分组后组内排序 (2)指定计算范围 (3)Top N (4)累加计算 (5)层次计算 分析函数的一般语法: 分析函数的语法结构一般是: 分析函数名(参数)  over  ...

  2. 43. 守护线程 和 join方法

    1.守护线程(后台线程):            我们在使用一款软件的时候,有的软件会让我们在不知道的情况下下载一些东西,那么这个就是后台线程.            一般用于提高软件的下载量(也就是 ...

  3. Winform 奇怪的 英文字体错乱显示问题

    效果如图: 字体是Calibri 后来看了一下,我在vs设计器中为了预览效果定义了这些中文,然后在构造函数中将其改成英文,可能是已经为中文渲染出了位置?在改变就会冲突? 我的设计器 如何修改: 将vs ...

  4. Batch - windows batch 常用命令(cheat sheet)

    原文地址:https://www.oschina.net/code/snippet_158297_4964 1 echo 和 @ 回显命令 @ #关闭单行回显 echo off #从下一行开始关闭回显 ...

  5. linux安装MySQL-5.6.22-1.el6.i686.rpm-bundle.tar

    1.首先搜索系统有没有安装过mysql,使用命令 rpm -qa|grep mysql 有的话先卸载 rpm -e --nodeps  + mysql应用名字\ 2.在/usr/local下创建mys ...

  6. 线段树区间离散化——牛客多校E

    这个区间离散化把我调死了.. 总之用vector来离散化,然后叶子节点维护的是一段区间,记录下每个叶子结点的起点+长度 千万要注意下标不能弄错! #include<bits/stdc++.h&g ...

  7. NX二次开发-如何在类外面定义一个结构体

    #include <uf.h> #include <uf_obj.h> #include <uf_part.h> using namespace NXOpen; u ...

  8. Spring随笔-bean装配

    Spring提供了三种装配方式 1.XML文件进行显式装配 2.java中进行显示装配 3.自动化装配 1.自动化装配的两种实现方式 1.组件扫描:Spring会自动发现应用上下文中创建的bean 2 ...

  9. jQuery 基本选择器

    1 基本选择器 $(‘#id属性值’)  ----------->document.getElementById() $(‘tag标签名称’)----------->document.ge ...

  10. 基于三角形与位置指纹识别算法的WiFi定位比较

    文章来着:https://wenku.baidu.com/view/55d1f4146edb6f1aff001fec.html