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. 保护Laravel .env文件,防止直接访问

    web服务器: Apache 服务器系统: Ubuntu 14.04 如果不是vhost的形式部署在服务器上,可能是可以通过 http://www.example.com/.env 查看到larave ...

  2. jq-demo-放大镜

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. CTF学习路线指南(附刷题练习网址)

    PWN,Reverse:偏重对汇编,逆向的理解: Gypto:偏重对数学,算法的深入学习: Web:偏重对技巧沉淀,快速搜索能力的挑战: Mic:则更为复杂,所有与计算机安全挑战有关的都算在其中 常规 ...

  4. php 使用fseek指针读取大文件日志

    function text($fp,$n,$b=5) { if($n>0){ $p = $n+1; $lines = array(); while(count($lines)< =$n){ ...

  5. js特效玫瑰花

    <script> var b = document.body; var c = document.getElementsByTagName('canvas')[0]; var a = c. ...

  6. Dart编程判断

    条件/决策构造在执行指令之前评估条件. 下表是Dart中的条件语句 序号 声明和说明 1 if 语句 一个if语句由一个布尔表达式后跟一个或多个语句. 2 If...Else 语句 一个if可以跟一个 ...

  7. Ruby 类和对象

    Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...

  8. Codeforces 1168A Increasing by Modulo

    题目链接:http://codeforces.com/problemset/problem/1168/A 题意:给一个数组,数组中元素范围为0~n,每次你可以选择若干元素进行(ai+1)%m的操作,问 ...

  9. 剑指offer——03替换空格

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy.   注意事项: <剑指o ...

  10. Rabbit MQ 基础入门

    Rabbit MQ 学习(一)基础入门 简介 RabbitMQ 简介 为什么选择 RabbitMQ RabbitMQ 的模型架构是什么? AMQP 协议是什么? AMQP 常用命令 概念 生产者和消费 ...