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反射技术实例
java反射技术实例1. [代码][Java]代码 package com.gufengxiachen.java.reflectiontest; public class Person {p ...
- BluetoothLELibrary 支持1对1连接
github地址:https://github.com/qindachang/BluetoothLELibrary 该库只支持1对1连接,如果你想1对多设备连接,请移步至 BluetoothLE-Mu ...
- http://www.cnblogs.com/yaozhenfa/archive/2015/06/14/4574898.html
笔者这里采用的是mongoDB官网推荐使用.net驱动: http://mongodb.github.io/mongo-csharp-driver/2.0/getting_started/quick_ ...
- Mysql数据库的打开和关闭
Mysql数据库的打开和关闭: 选择计算机(win7)-右键管理 在新窗口选择--服务 5 找到mysql,然后右键-启动(停止)
- Request.UrlReferrer 实现页面刷新
在使用Ajax 异步提交表单的时候,需要返回某些状态信息.但如果把需要返回的如分页.过滤的参数写在控制器的参数里面,会比较繁琐. 因此,1.可以在控制器里面使用 Request 对象的请求的URL. ...
- 12_tcp_ip相关概念
java基础班 网络编程应该提过.大学学计算机或者是通信的对这些东西肯定比较熟一些.主机到网络层是跟硬件相关的一些协议了.上层协议得依赖下层的协议.也就是说它们得联合起来共同工作才能够把数据传输出去 ...
- Monkey学习(转载)
Monkey测试特点 什么是Monkey test? 如其名,像猴子一样,虽然什么都不懂,但是可以乱点一通,可以理解为压力测试.在规定的时间或次数范围内做任何随机的操作,随即操作包括点击.滑动.... ...
- 3.16 使用Zookeeper对HDFS HA配置自动故障转移及测试
一.说明 从上一节可看出,虽然搭建好了HA架构,但是只能手动进行active与standby的切换: 接下来看一下用zookeeper进行自动故障转移: # 在启动HA之后,两个NameNode都是s ...
- 解决 'chromedriver' executable needs to be in PATH.'报错
试了把chromedriver.exe放到chrome安装文件下,python安装文件下,然后把路径配到path里,均无用. 最后是修改函数调用得以解决: from selenium import w ...
- 4-1数据类型转换的基本概念 & 4-2 & 4-3数据类型转换案例 & 4-4习题
4-1数据类型转换的基本概念 253是int类型的,赋值给长整型的n 这种就是强制的类型转换 自动类型转换又叫做饮食类型转换,因为他的转换我们是看不到的 实线表示无数据丢失的 虚线在转换时, doub ...