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的倍数,数字可以重 ...
随机推荐
- java实现EXCEL数据导入到数据库中的格式问题的解决
之前作为项目甲方,加之java接触不多,在java web开发方面都是打下手的份. 对于EXCEL数据导入到数据库这个问题一直老是出现格式原因而导入失败也是未免惆怅,开发团队也是只说回去检查一下格式. ...
- BZOJ_3729_Gty的游戏_博弈论+splay+dfs序
BZOJ_3729_Gty的游戏_博弈论+splay+dfs序 Description 某一天gty在与他的妹子玩游戏. 妹子提出一个游戏,给定一棵有根树,每个节点有一些石子,每次可以将不多于L的石子 ...
- button的FlatStyle和FlatAppearance属性
FlatStyle是处理边框的样式,而FlatAppearance是用来设置边框的颜色,宽度和鼠标移动和点击时的效果设置FlatStyle为Flat,并且设置FlatAppearance下的Borde ...
- bzoj3625
fft 分治虽然是万能的,但是太慢了 分治是nlog^2n的,太慢了,于是我们用求逆和开根 设f(x)表示答案为x的方案数 c表示物品的生成函数 那么f=f*f*c+1 f*f表示左右儿子的方案数 c ...
- SQL Server 盛宴系列 webcast
数据库学习站点,示例,视频 http://technet.microsoft.com/zh-cn/dd722671.aspx
- Eclipse中导入Hadoop源代码工程
以hadoop 2.7.3为例, jdk1.7.0_80 , Eclipse Mars(4.5), Apache Maven 3.0.5 mvn时需要使用root权限,即县切换到root用户,用命 ...
- .Net框架中的CLR,CTS,ClS的解释
CLR的全称(Common Language Runtime) 公共语言运行时 可以把它理解为包含运行.Net程序的引擎 和 一堆符合公用语言基础(CLI)的类库的集合,他是一个规范的实现,我们开发的 ...
- Java代码加密与反编译(一):利用混淆器工具proGuard对jar包加密
Java 代码编译后生成的 .class 中包含有源代码中的所有信息(不包括注释),尤其是在其中保存有调试信息的时候.所以一个按照正常方式编译的 Java .class 文件可以非常轻易地被反编译.通 ...
- Identity Server 4 原理和实战(完结)_Hybrid Flow 实例, Claims, 角色授权和策略授权
4分50 建立客户端 不需要身份认证 客户端叫做HybirdClient 配置IdentityServer服务端,先把客户端添加上 把userClaims添加到token里面 然后运行服务端就可以了 ...
- 关于window 查看端口命令
今天小R又知道了一个新的小常识,个人觉得还是蛮实用的,可能对于有些新手来讲应该也不知道吧. 如:大家都知道window查看命令是用 “netstat -an” , 如图显示一大推打开的端口. 但 ...