题目描述

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 is given from Standard Input in the following format:
N
a1 a2 … aN

输出

Print the answer.

样例输入

6
1 2 3 4 5 6

样例输出

1

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
const int mxn=2e5+;
LL n,num[mxn],sum[mxn],SUM;
void init(){
cin>>n;
range(i,,n){
cin>>num[i];
sum[i]=sum[i-]+num[i];
SUM+=num[i];
}
}
void solve(){
LL MIN=0x7f7f7f7f;
range(i,,n-)if(MIN>abs((sum[i]<<)-SUM))MIN=abs((sum[i]<<)-SUM);
cout<<MIN<<endl;
}
int main() {
init();
solve();
return ;
}

Splitting Pile --AtCoder的更多相关文章

  1. Splitting Pile

    Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snuke a ...

  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. AtCoder Beginner Contest 085(ABCD)

    A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...

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

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

  8. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

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

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

随机推荐

  1. 重写BaseAdapter实现ListView

    public class BaseAdapterActivity extends BaseActivity { private ListView base_adapter_listView; priv ...

  2. OpenCV学习笔记(五) 文件存取

    转自输入输出XML和YAML文件 To be filled

  3. dotnet core 2.2 安装后在vs2017中无法选择 dotnet core 2.2 为目标框架

    可能有效的解决方案: 无法完全保证有效,因为我本地装上没问题,只帮同事解决过一次,貌似有效 方案就是多装几个 .net core 2.2.xxx 版本,然后可能就正常识别了. 在安装之前,先把 vs ...

  4. loj2045 「CQOI2016」密钥破解

    CQOI 板子大赛之 pollard rho #include <iostream> #include <cstdio> using namespace std; typede ...

  5. Bugku杂项-convert

    一进去就发现一堆二进制数,然后考虑怎么才能把这个和隐写扯上关系.首先,二进制我们肉眼就是看不懂再说什么的,这里就想到了转换,再联想上hex将原始数据转化为16进制.我们可以先把2进制转化为16进制,然 ...

  6. c++ 吕凤翥 第六章 类和对象(二)

    c++ 吕凤翥 第六章 类和对象(二) 指针   引用  和数组 一:对象指针和对象引用 1.指向类的成员的指针 分为指向成员变量和指向成员函数两种指针 成员变量的格式:     类型说明符  类名: ...

  7. Java 语言概述与开发环境(1)

    目录: 一.计算机语言的发展史 二.Java语言的简述 三.Java的特点 四.java语言的运行环境及环境变量的配置 五.Dos的常见命令 六.第一个java程序-HelloWord        ...

  8. 菜鸟之路——机器学习之线性回归个人理解及Python实现

    这一节很简单,都是高中讲过的东西 简单线性回归:y=b0+b1x+ε.b1=(Σ(xi-x–)(yi-y–))/Σ(xi-x–)ˆ2       b0=y--b1x-    其中ε取 为均值为0的正态 ...

  9. [oldboy-django][2深入django]学生管理(Form)-- 添加(美化Form表单:通过form给前端标签添加属性)

    1 在student_list添加一个a标签, <p><a href="/app01/add_student" class="btn btn-prima ...

  10. scp -v 查看具体的过程

    前几天跟同事讨论scp 多个文件和 scp多个文件夹的压缩包那个快. 老大说,压缩包快,压缩包传输可以避免每个文件的重建连接,不过文件系统的遍历.目录创建.检验会有一些开销. 他建议我scp -v看下 ...