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. Unity导出webPlayer并且部署到IIS

    http://blog.csdn.net/zooen2011/article/details/12884811 做好的Unity3D项目工程导出webPlayer类型,本地可以直接打开导出的html文 ...

  2. lodash forIn forOwn 遍历对象属性

    _.forIn(object, [iteratee=_.identity]) 使用 iteratee 遍历对象的自身和继承的可枚举属性. function Foo() { this.a = 1; th ...

  3. 常见的开发语言(或IT技术)一览

    Java. Android. iOS. Web前端. Python. .NET. PHP. C/C++. Linux 数据库技术

  4. js中数组的splice()方法

    在数组中splice方法有增.删.该的多功能用处. var list = []; list.push(1); list.push(2); list.push(3); console.log(list) ...

  5. 获取request中的查询参数

    //获取request中的查询参数 public static Map<String, Object> getRequestParamsByMap(HttpServletRequest r ...

  6. 使用jconsole监控tomcat(推荐配置)

    1.在tomcat启动过程中,开启相应的参数配置 $Tomcat_home/bin/catalina.sh: 1 2 3 4 -Dcom.sun.management.jmxremote -Dcom. ...

  7. 通过浏览器查看nginx服务器状态配置方法

    通过浏览器查看nginx服务器状态配置方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了通过浏览器查看nginx服务器状态配置方法,本文讲解开启nginx-status的配 ...

  8. C#取调用堆栈StackTrace

    Environment.StackTrace or System.Diagnostics.StackTrace if you need a more convienient (i.e. not str ...

  9. C语言基础(20)-文件操作(fopen,getc,fclose)

    一.文件操作 读文件的顺序: 1.先打开文件 2.读写文件 3.关闭文件 1.1 fopen FILE *fopen( const char *path, const char *mode ); 函数 ...

  10. AF_UNIX和AF_INET域的socket在epoll中的差异

    1.AF_UNIX & SOCK_STREAM 1.1 accept_socket BLOCK EPOLLIN|EPOLLET 1.2 accept_socket NON-BLOCK EPOL ...