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=10y=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=10y=−10, and thus |x−y|=20.

题意:一共有n张牌,A拿走前面的至少一张,最多只剩一张,B拿走剩下的,问他们各自的牌的和的绝对值差最小是多少?

直接暴力得了,把所有能拿的情况都列出来,然后排个序ok

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 200010 LL a[MX];
LL ans[MX]; int main()
{
int n;
scanf("%d",&n);
LL sum=;
for(int i=;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
LL x = a[];
LL y = sum-a[];
ans[]=abs(x-y);
for (int i=;i<n-;i++)
{
x+=a[i];
y-=a[i];
ans[i]=abs(x-y);
}
sort(ans,ans+n-);
cout<<ans[]<<endl;
return ;
}

Splitting Pile的更多相关文章

  1. Splitting Pile --AtCoder

    题目描述 Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written ...

  2. AtCoder Beginner Contest 067 C - Splitting Pi

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  3. AtCoder Regular Contest 078

    我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...

  4. 【AtCoder】ARC078

    C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...

  5. AtCoder Regular Contest 078 C

    C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...

  6. 关于 Word Splitting 和 IFS 的三个细节

    在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...

  7. Educational Codeforces Round 4 A. The Text Splitting 水题

    A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...

  8. bzoj4578: [Usaco2016 OPen]Splitting the Field

    2365: Splitting the Field 题意:n个点,求用两个矩形面积覆盖完所有点和一个矩形覆盖完少多少面积 思路:枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点:先预处理每 ...

  9. [Webpack 2] Maintain sane file sizes with webpack code splitting

    As a Single Page Application grows in size, the size of the payload can become a real problem for pe ...

随机推荐

  1. iOS wkwebview和 uiwebview 内容图片自适应大小

    - (void)webViewDidFinishLoad:(UIWebView *)webView { // 2.都有效果 NSString *js=@"var script = docum ...

  2. javaSE中的输入输出流---一个读取流,相应多个输出流。并且生成的碎片文件都有有序的编号

    <span style="font-size:18px;">package com.io.other.split; import java.io.File; impor ...

  3. 原生 javascript 基础回顾

    (1)打开新窗口 语法: window.open([URL], [窗口名称], [参数字符串]) 参数说明: URL:可选参数,在窗口中要显示网页的网址或路径.如果省略这个参数,或者它的值是空 字符串 ...

  4. CSS Flexible 布局兼容性以及解决方案

    1.兼容性 https://caniuse.com/#feat=flexbox IE11以及以下不支持. 2.解决方案 flexibility库 https://github.com/jonathan ...

  5. libevent2源码分析之三:信号的初始化流程

    libevent2对信号的响应也进行了封装,使之与socket操作一样对外提供统一的接口.这里的信号一般指linux的信号.由于信号与socket相关的编程接口有较大的不同,因此在内部实现也有一些区别 ...

  6. LoadRunner+Java接口性能测试

    想必各位小伙伴们会对LR还可以调用java感到好奇,之前我也这么一直认为LR只支持C语言.其实LR脚本支持的语言有:C.Java.Visual Basic.VbScript.JavaScript,只不 ...

  7. ftp获取远程Pdf文件

    此程序需要安装ftp服务器,安装adobe reader(我这里使用的adobe reader9.0) 1.部署ftp服务器 将ftp的权限设置为允许匿名访问,部署完成 2.安装adobe reade ...

  8. zabbix proxy 安装

    ### 前期准备 ```   # 直接yum安装 ```   ### 安装 ``` # 安装 sqlite zabbix-proxy-sqlite3 yum -y install sqlite sql ...

  9. Android JNI和NDK学习(01)--搭建NDK开发环境(转)

    本文转自:http://www.cnblogs.com/skywang12345/archive/2013/05/23/3095013.html 本文主要介绍“JNI”.“Android NDK”以及 ...

  10. unity mac 破解教程

    1.安装好软件,我们解压破解包,有下面两个文件,Unity 和Unity_v5.x.ulf,放桌面.     2.打开终端.       3.输入文件地址,注意,我这上边的用户名,记得改成自己的用户名 ...