C - 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 |xy|. Find the minimum possible value of |xy|.

Constraints

  • 2≤N≤2×105
  • −109ai≤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

Copy
6
1 2 3 4 5 6

Sample Output 1

Copy
1

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


Sample Input 2

Copy
2
10 -10

Sample Output 2

Copy
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 |xy|=20.

题意:选取顶端区间数字求和,再取剩余数字求和,问他们的绝对值之差最小为多少?

解法:当然是前缀和啦~~~~

 #include<bits/stdc++.h>
#define N 2*123456
using namespace std;
#define LL long long
LL a[N];
LL sum[N+],sum2[N+];
LL Min=0x3f3f3f3f3f3f3f3f;
int main(){
LL n,m;
scanf("%lld",&n);
sum[]=;
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-]+a[i];
}
for(int i=;i<=n-;i++){
// cout<<abs(sum[i]-(sum[n]-sum[i]))<<" "<<Min<<endl;
Min=min(abs(sum[i]-(sum[n]-sum[i])),Min);
}
printf("%lld\n",Min);
return ;
}

AtCoder Regular Contest 078 C的更多相关文章

  1. AtCoder Regular Contest 078

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

  2. AtCoder Regular Contest 078 D

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  3. AtCoder Regular Contest 061

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

  4. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  5. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  6. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  7. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  8. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  9. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

随机推荐

  1. 数据结构之 字符串---字符串匹配(kmp算法)

    串结构练习——字符串匹配 Time Limit: 1000MS Memory limit: 65536K 题目描述   给定两个字符串string1和string2,判断string2是否为strin ...

  2. js获取浏览器宽高、网页宽高、屏幕宽高、鼠标位置等(带图片说明)

    网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;(点击查看大图) 网页可见区域宽: document.bo ...

  3. Struts2 拦截器配置及使用

    在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...

  4. Add GNOME to a CentOS Minimal Install

    by Jeff Hunter, Sr. Database Administrator Contents Introduction CentOS 6 About the Author Introduct ...

  5. HihoCoder 1488 : 排队接水(莫队+树状数组)

    描述 有n个小朋友需要接水,其中第i个小朋友接水需要ai分钟. 由于水龙头有限,小Hi需要知道如果为第l个到第r个小朋友分配一个水龙头,如何安排他们的接水顺序才能使得他们等待加接水的时间总和最小. 小 ...

  6. POJ1236 Network of Schools (强连通分量,注意边界)

    A number of schools are connected to a computer network. Agreements have been developed among those ...

  7. c++之函数值传递和引用传递解析----关键在于理解函数return的实现机制(内存分配)

    函数调用过程解析 func里的a存储在调用fun函数时开辟的栈空间里,这块栈只在调用func时对func可用,调用结束后返回的a,其实是暂存在寄存器里的(一般情况下是eax),而返回到main里时,m ...

  8. 做一名开源社区的扫地僧——从Bug report到Google Summer of Code(GSoC):从200个bug到5000美金

    今年的软件自由日(SFD),我在广州Linux用户组的线下活动上做了一个分享,主题叫做<做一名开源社区的扫地僧(上)>.我把演讲的内容重新整理扩充, 写出了文字版, 希望可以跟更多朋友分享 ...

  9. PHP中正则表达式学习及应用(四)

    正则表达式在PHP中的应用 1.匹配功能 2.替换功能 3.分割功能 例如: <?php $str="addsds{title}hfksjd{author}hfjdkjd{conn}j ...

  10. 洛谷1303 A*B Problem 解题报告

    洛谷1303 A*B Problem 本题地址:http://www.luogu.org/problem/show?pid=1303 题目描述 求两数的积. 输入输出格式 输入格式: 两个数 输出格式 ...