CodeForces - 667B Coat of Anticubism (数学几何规律)

CodeForces - 667B
Coat of Anticubism
Time Limit:                                                        1000MS                          Memory Limit:                                                        262144KB                          64bit IO Format:                            %I64d & %I64u                       

SubmitStatus

Description

As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.

A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.

Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The i-th rod is a segment of length li.

The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .

Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.

Help sculptor!

Input

The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks.

The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.

Output

Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.

Sample Input

Input
3
1 2 1
Output
1
Input
5
20 4 3 2 1
Output
11

Sample Output

Hint

Source

Codeforces Round #349 (Div. 2)
//题意:输入n,再输入n个数,表示有n根长度不同的木棒。
问要从这些木棒的长度中最少截取多长才能使得他们组成一个凸多边形。
//思路:
可以将它简化一下,让他组成三角形(最简单的凸多边形),接着就是判断组成三角形的条件了,很简单的题(关键在转化)。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
#define N 100010
using namespace std;
ll a[N];
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		ll sum=0;
		for(i=0;i<n;i++)
			scanf("%lld",&a[i]),sum+=a[i];
		sort(a,a+n);
		sum-=a[n-1];
		if(sum>a[n-1])ws
			printf("0\n");
		else
			printf("%lld\n",a[n-1]-sum+1);
	}
	return 0;
} 

你可能感兴趣的:(CodeForces - 667B Coat of Anticubism (数学几何规律))