AtCoder Regular Contest 078 C
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 |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=10, y=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=10, y=−10, and thus |x−y|=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的更多相关文章
- AtCoder Regular Contest 078
我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...
- AtCoder Regular Contest 078 D
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
- AtCoder Regular Contest 095
AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
随机推荐
- 网页兼容性测试(工具使用IETESTER、Firefox、360安全浏览器)
网页兼容性测试主要是针对不同的浏览器进行的测试.由于用户浏览器的不同,往往都会使我们的网页发生页面样式错乱,图片无法显示等问题.对于前端开发工程师来说,确保代码在各种主流浏览器的各个版本中都能正常显示 ...
- 为 Android 平台开发一个输入法
学习目标: 实现新的输入法 学习目的: 掌握Android输入法框架 学习收获: Android 1.5 新特色之一就是输入法框架(Input Method Framework,IMF),正是它的出现 ...
- linux应用之gcc编译器的安装及使用
gcc是linux系统下功能十分强大的编译器. 本人使用的是CentOS 6.6 64位系统,由于在安装系统的时候并没有勾选安装gcc编译器,因此需要自行安装gcc编译器. 使用yum安装gcc 对于 ...
- cassandra压缩——从文档看,本质上也应该是在做块压缩
Compression Compression maximizes the storage capacity of Cassandra nodes by reducing the volume of ...
- nginx + ffmpeg
第一种方案:ffmpeg+nginx 新的ffmpeg已经支持HLS.(本人也参与了代码供献,给自己做个广告:)) 点播: 生成hls分片: ffmpeg -i <媒体文件> -c:v l ...
- HDU2602(01背包)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- bzoj4004
线性基 构成线性基的个数是定的,所以我们对价值进行贪心就行了,根据拟阵那套理论,我们排个序,然后能塞进去就塞,这样就求出最小值了. 思维江化,只要是多维向量都能用线性基搞. #include<b ...
- redis实例
<?php Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 本篇文章,主要介绍利用PHP使用Redis ...
- iOS 中这些是否熟练掌握——(2)
接上一篇博文,本篇博文是作者原创,用于记录从网上查阅的一些资料,并对自己的知识体系进行一下总结,成文以供学习使用. 1.Cocoa Touch 包含了什么?不包含什么?与 Cocoa 有什么区别? 相 ...
- World CodeSprint 10
C: 题意: 给定一个长度为 $n$ 的序列 $a_i$,从 $a$ 序列中选出一个大小为 $k$ 的子序列使得子序列数字的 bitwise AND 值最大. 求问最大值是多少,并求出有多少个最大值 ...