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. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何配置虚拟轴 TC3

    在Motion上添加一个NC Task   在Axis上右击添加一个轴,类型为Continuous Axis   在PLC上右击添加新项,然后添加一个PLC项目   在引用中添加TC2_MC2的库引用 ...

  2. 入侵者已经拿到了主机的管理员权限,请你列举几种留后门的方法:(windows和LINUX系统均可)

    Webshell后门 XSS后门 远控后门&rootit(windows&LINUX) SSH后门 SHIFT终端服务器后门 系统用户账号克隆 SQL数据库扩展存储型后门 SQL数据库 ...

  3. B6:命令模式 Command

    将一个请求封装成一个对象,从而可以用不同的请求对象对客户进行参数化,对请求排队或记录请求日志,以及支持可撤销的操作. 与状态模式和责任链模式的区别是,命令模式设定一次,统一执行 使用场景:1.可设计一 ...

  4. re中match和search的不同

    re.match与re.search的区别:re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None:而re.search匹配整个字符串,直到找到一个匹配.

  5. hadoop english

    for the same 同样previously 之前地overlay v. 覆盖; 镀金variable expansion 变量替换processed for 处理 entry(entries) ...

  6. 简单模拟Spring的注入

    主要就是读XML技术和反射技术. 在xml中读出相关配置信息,然后利用反射将其实例化为对象,并调用其构造方法,在实例化的过程中将属性注入实例. 实例化和属性注入这些操作都交给了框架,不再需要自己的去n ...

  7. php中在局部作用域内访问全局变量

    php中,由于作用域的限制,导致变量的访问限制: 1.局部作用域内不能访问全局变量 2.全局作用域内不能访问局部变量 对于第一种情况,如下代码将不能正常运行: <?php //局部作用域(函数内 ...

  8. Rest API By JAX-RS 实现接口发布

    原文地址:http://www.cnblogs.com/oopsguy/p/7503589.html JAX-RS 我们在 JAX-RS 示例中使用相同的模型和 DAO,我们所需要做的只有更改 Sto ...

  9. NSTimer 增加引用计数, 导致内存泄露,

    self.adTimer   = [NSTimerscheduledTimerWithTimeInterval:5.0target:selfselector:@selector(handleADIma ...

  10. MVC Controller return 格式之JsonResult、ContentResult、RedirectResult……

      //语法 public class JsonResult : ActionResult public class ContentResult : ActionResult public class ...