Splitting Pile


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written on it.

They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x−y|. Find the minimum possible value of |x−y|.

Constraints

  • 2≤N≤2×105
  • −109≤ai≤109
  • ai is an integer.

Input

Input is given from Standard Input in the following format:

N
a1 a2 aN

Output

Print the answer.


Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10y=11, and thus |x−y|=1. This is the minimum possible value.


Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10y=−10, and thus |x−y|=20.

题意:一共有n张牌,A拿走前面的至少一张,最多只剩一张,B拿走剩下的,问他们各自的牌的和的绝对值差最小是多少?

直接暴力得了,把所有能拿的情况都列出来,然后排个序ok

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 200010 LL a[MX];
LL ans[MX]; int main()
{
int n;
scanf("%d",&n);
LL sum=;
for(int i=;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
LL x = a[];
LL y = sum-a[];
ans[]=abs(x-y);
for (int i=;i<n-;i++)
{
x+=a[i];
y-=a[i];
ans[i]=abs(x-y);
}
sort(ans,ans+n-);
cout<<ans[]<<endl;
return ;
}

Splitting Pile的更多相关文章

  1. Splitting Pile --AtCoder

    题目描述 Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written ...

  2. AtCoder Beginner Contest 067 C - Splitting Pi

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  3. AtCoder Regular Contest 078

    我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...

  4. 【AtCoder】ARC078

    C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...

  5. AtCoder Regular Contest 078 C

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  6. 关于 Word Splitting 和 IFS 的三个细节

    在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...

  7. Educational Codeforces Round 4 A. The Text Splitting 水题

    A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...

  8. bzoj4578: [Usaco2016 OPen]Splitting the Field

    2365: Splitting the Field 题意:n个点,求用两个矩形面积覆盖完所有点和一个矩形覆盖完少多少面积 思路:枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点:先预处理每 ...

  9. [Webpack 2] Maintain sane file sizes with webpack code splitting

    As a Single Page Application grows in size, the size of the payload can become a real problem for pe ...

随机推荐

  1. Nginx主动连接与被动连接的差别

    1.主动连接是指Nginx主动发起的同上游server的连接:被动连接是指Nginx接收到的来自client主动发起的连接; 2.主动连接用ngx_peer_connection_t结构体表示:被动连 ...

  2. zabbix监控redis的key值

    配置zabbix客户端配置文件 vim /etc/zabbix/zabbix_agentd.conf 添加  Include=/etc/zabbix/zabbix_agentd.d/ 添加脚本对red ...

  3. Quartz简介 用 Quartz 进行作业调度

    http://www.ibm.com/developerworks/cn/java/j-quartz/现代的 Web 应用程序框架在范围和复杂性方面都有所发展,应用程序的每个底层组件也必须相应地发展. ...

  4. 【转载】HTTP和SOAP完全就是两个不同的协议

    http:是一个客户端和服务器端请求和应答的标准(TCP). http协议其目的是为了提供一种发布和接收htttp页面的方法 http协议的客户端与服务器的交互:由HTTP客户端发起一个请求,建立一个 ...

  5. tomcat的安装、配置

    简单介绍 Tomcat server是一个免费的开放源码的Web 应用server,属于轻量级应用server, 在中小型系统和并发訪问用户不是非常多的场合下被普遍使用,是开发和调试JSP 程序的首选 ...

  6. Linux操作系统桌面环境GNOME和KDE的切换

    一.设置GNOME或者KDE为默认的启动桌面环境 方法1:修改/etc/sysconfig/desktop,根据需要将“DESKTOP”后面的内容改为KDE或GNOME. 方法2:在当前用户目录下建立 ...

  7. Atitit.  Js 冒泡事件阻止 事件捕获   事件传递  事件代理

    Atitit.  Js 冒泡事件阻止 事件捕获   事件传递  事件代理   1. 事件冒泡1 2. 事件捕获1 3. 同时支持了事件捕获阶段和事件冒泡阶段ddEventListener的第三个参数1 ...

  8. gcc支持的标签

    #include <stdio.h> #include <time.h> int main(/*int argc, char const *argv[]*/) { void * ...

  9. JsCal( JS Calendar)

    http://www.dynarch.com/projects/calendar Doc: http://www.dynarch.com/jscal/ This is the documentatio ...

  10. RTT常用数据类型

    RTT常用数据类型定义在rtdef.h中 /* RT-Thread basic data type definitions */ typedef signed char rt_int8_t; /**& ...