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

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 |xy|=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 |xy|=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的更多相关文章

  1. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  2. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  3. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  4. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  5. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  6. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  7. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  8. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  9. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

随机推荐

  1. Myeclipse学习总结(8)——Eclipse实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个"器".本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行 ...

  2. centos7.x86_64搭建饥荒服务器

    http://blog.ttionya.com/article-1233.html 在centos7下找不到 libcurl-gnutls.so.4,而且必须要安装32位的才行 yum install ...

  3. 和同事合作开发,使用局域网 git创建本地仓库

    转自原文 和同事合作开发,使用局域网 git创建本地仓库 1.仓库 建一个空文件夹来做仓库,例如建为 cangku 1.1 cd 到 cangku目录下 创建远程仓库容器 mkdir  mycangk ...

  4. 待字闺中之Magic Index 分析

    给定一个数组A,当中有一个位置被称为Magic Index,含义是:如果i是Magic Index.则A[i] = i. 如果A中的元素递增有序.且不反复,请给出方法,找到这个Magic Index. ...

  5. POJ 1741 Tree 树的分治(点分治)

    题目大意:给出一颗无根树和每条边的权值,求出树上两个点之间距离<=k的点的对数. 思路:树的点分治.利用递归和求树的重心来解决这类问题.由于满足题意的点对一共仅仅有两种: 1.在以该节点的子树中 ...

  6. PHP使用数组实现队列(实际就是先进先出怎样实现)

    PHP的数组处理函数还能够将数组实现队列,堆栈是"先进后出". 在堆栈中,最后压入的数据(进栈),将会被最先弹出(出栈).而队列是先进先出.就如同银行的排号机 PHP中将数组当做一 ...

  7. Session原理、安全以及最基本的Express和Redis实现

    Session原理.安全以及最基本的Express和Redis实现 https://segmentfault.com/a/1190000002630691

  8. [ xml ] [ log4j2 ] No grammar constraints (DTD or XML Schema) referenced in the document.

    <!DOCTYPE xml> http://rx1226.pixnet.net/blog/post/321584550

  9. vuejs scope

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. NodeJS学习笔记 (26)命令行设计-repl

    https://github.com/chyingp/nodejs-learning-guide