AtCoder Beginner Contest 067 C - Splitting Pi
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 <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll x,sum[],n,ans,minn;
int main()
{
scanf("%lld",&n);
sum[]=;
for(ll i=;i<=n;i++)
{
scanf("%lld",&x);
sum[i]=sum[i-]+x;
}
ans=sum[n];
minn=abs(*sum[]-sum[n]);
for(ll i=;i<=n-;i++)
{
minn=min(minn,abs(*sum[i]-sum[n]));
}
printf("%lld\n",minn);
return ;
}
AtCoder Beginner Contest 067 C - Splitting Pi的更多相关文章
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
随机推荐
- 现代C++
C++ 是世界上最常用的编程语言之一. 编写良好的 C++ 程序是快速.高效的. 该语言比其他语言更加灵活,因为你可以使用它来创建各种应用,包括有趣刺激的游戏.高性能科学软件.设备驱动程序.嵌入式程序 ...
- android:Activity启动模式之singleTask(一)
先看一下standard启动模式的说明: 仅仅有一个实例.在同一个应用程序中启动他的时候.若不存在此Activity实例.则会在当前栈顶创建一个新的实例.若存在,则会把栈中在其上的其他Activity ...
- iPhone4怎样鉴别翻新机
加入杂志 步骤 1 2 3 4 5 6 由于iPhong4s的不给力,中国内地上市时间又尚未确定,造成近期iPhone4的价格涨了一大截,随之而来的就是大量的翻新机出现在市场上,那么 怎样判断自己手中 ...
- 多线程02---pThread简单介绍
1.简单介绍 pthread 是属于 POSIX 多线程开发框架. 它是c语言提供的一个跨平台的多线程解决方式.因为其在iOS编程中,操作比較麻烦.一般不用,这里介绍只作为了解. 2.pthread的 ...
- 36.创建模板mylist
node.h #pragma once //创建模板 template <class T> class Node { public: T t;//数据 Node *pNext;//指针域 ...
- POJ 3661 DP
题意: 思路: i表示到了i,j表示疲劳度为j f[i][j]表示能跑的最大距离 f[i][j]=f[i-1][j-1]+a[i] if(i-j>=0)f[i][0]=max(f[i][0],f ...
- spring的quartz定时任务
一.版本: 1.spring:4.1.7: 2.quartz:2.2.1: 二.基于ssm项目: 1.引入jar包:quartz-2.2.1.jar:spring所需包. 2.说明:quartz ...
- 关于网易云音乐爬虫的api接口?
抓包能力有限,分析了一下网易云音乐的一些api接口,但是关于它很多post请求都是加了密,没有弄太明白.之前在知乎看到过一个豆瓣工程师写的教程,但是被投诉删掉了,请问有网友fork了的吗?因为我觉得他 ...
- pip源
阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣(do ...
- php动态导出数据成Excel表格
一.封装 Excel 导出类 include/components/ExecExcel.php <?php /*** * @Excel 导入导出类. */ class ExecExcel { / ...