题意:

输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
sort(a+,a++n);
long long sum=,sum2=;
for(int i=;i<=n/;++i)
sum+=a[i];
for(int i=n/+;i<=n;++i)
sum2+=a[i];
cout<<n%<<" "<<sum2-sum;
return ;
}

【PAT甲级】1113 Integer Set Partition (25分)的更多相关文章

  1. PAT 甲级 1113 Integer Set Partition

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

  2. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  3. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

  4. PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)

    1074 Reversing Linked List (25 分)   Given a constant K and a singly linked list L, you are supposed ...

  5. PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习

    1086 Tree Traversals Again (25分)   An inorder binary tree traversal can be implemented in a non-recu ...

  6. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  7. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  8. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  9. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

随机推荐

  1. ASP.NET Identity系列教程-4【Identity高级技术】

    https://www.cnblogs.com/r01cn/p/5194257.html 15 ASP.NET Identity高级技术 In this chapter, I finish my de ...

  2. SDN-数据控制分离

    严格来说,控制面与数据面分离并不是SDN的专利.从一个chassis角度看,传统路由器其实控制面和转发面也是分离的.Route-enginee和line card分别负责控制面板和转发面.但是传统网络 ...

  3. PAT (Basic Level) Practice (中文)1037 在霍格沃茨找零钱 (20 分)

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.”现在,给定 ...

  4. nginx反向代理(1)

    目录 反向代理 概述 nginx代理 proxy_pass 加与不加/ ================================================================ ...

  5. linux100讲——12 创建和删除目录

    1.建立目录 mkdir    建立目录 常用参数 -p   建立多级目录 2.删除目录 rmdir  删除空目录 rm -r      删除非空目录  (删除时有提示) rm -r -f     删 ...

  6. Fastbin attack

    Fastbin Attack 暂时接触到了两种针对堆分配机制中fastbin的攻击方式,double free和house of spirit Double free 基本原理 与uaf是对free之 ...

  7. react-路由和Ant design

    路由的使用 react-router import React from 'react' // 如果要使用 路由模块,第一步,运行 yarn add react-router-dom // 第二步,导 ...

  8. Robot Framework选择定位option类型下拉框

    页面下拉框一般有两种类型,一种是div标签的,一种是option类型的,比如: div标签类型则可以通过定位进行元素点击去选择对应的枚举参数则可,而option类型的下拉选项则通过Selenium2L ...

  9. smarty文章字符截取

    {%$data.dealer_info.address|replace:' ':''|cutstr:58%} cutstr:58

  10. 在linux系统中配置NVMe over FC

    在linux系统中配置NVMe over FC与配置NVMe over TCP类似,前5步操作请参考<在linux系统中配置NVMe over TCP>,网页连接如下: https://w ...