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. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  2. easyui tree 树形节点 formatter 渲染不起作用

    接了个需求,需要对一个树形列表进行重新渲染,在进行渲染的过程中发现树形节点的formatter 属性无法生效.经反复测试,发现在外部环境中正常,但在项目环境中始终无效.最终发现问题出在 easyui ...

  3. plsql导入cvs 时提示missing right parenthesis

    删除自动生成的时间格式值,如:SQL function框里自动生成的值

  4. python中类的定义方法

    # coding =utf-8 ## 类的定义 ##-------------------------------------------------- class Employee: empCoun ...

  5. shiro加密简单实现

    1.添加shiro依赖 定义shiro的版本号 <shiro.ver>1.2.3</shiro.ver> 加入shiro的依赖 <dependency> <g ...

  6. CentOS 6 命令行下安装 VirtualBox 虚拟机步骤

    CentOS 6 命令行下安装 VirtualBox 虚拟机步骤 1. 准备工作 安装内核更新 yum install kernel-develyum update kernel*如果内核有更新,则需 ...

  7. androidEditTextinputType及android:imeOptions=”actionDone”(转)

    一.android 软件盘事件响应 在android中,有时需要对EditText实现软件盘监听的场景.当android按下软键盘的时候,响应完成.发送.搜索或者其他事件. Google 提供了 Ed ...

  8. LeetCode: 292 Nim Game(easy)

    题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...

  9. 洛谷 - P5429 - Fence Planning - 并查集

    https://www.luogu.org/problemnew/show/P5429 很明显是要维护整个连通块的共同性质,并查集一搞就完事了. #include<bits/stdc++.h&g ...

  10. hihocoder #1608 : Jerry的奶酪(状压DP)

    传送门 题意 分析 设dp[i][j]为在i状态下当前在第j个奶酪的最小费用 转移方程:dp[(1<<k)|i][k]=dp[i][j]+d[j][k] 预处理出每个奶酪之间的距离,加入起 ...