Coat of Anticubism
来源:互联网 发布:长沙市知豆电动怎么租 编辑:程序博客网 时间:2024/05/24 02:39
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!
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.
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.
31 2 1
1
520 4 3 2 1
11
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
/*题目大意:给你n个小木棍,保证不能组成三角形,让你填加一根小木棍(长度最短),使其能够组成三角形。思路:1、找到最大长度小木棍,作为斜边。2、累加比它小的所有小木棍的和,记做sum3、根据三角形:两边之差小于第三边:ans=最长小木棍-sum+1*/#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;#define ll __int64ll a[1000000];int main(){int k;while(scanf("%d",&k)!=EOF){for(int i=0;i<k;i++)scanf("%I64d",&a[i]);sort(a,a+k);ll sum=0;ll tt=a[k-1];for(int i=0;i<k-1;i++){sum+=a[i];}ll cnt=tt-sum+1;printf("%I64d\n",cnt);}}
- codeforces_667B. Coat of Anticubism
- Coat of Anticubism
- Codeforces 677 B.Coat of Anticubism【水题】
- Codeforces 667B - Coat of Anticubism(思维)
- Codeforces 667A Pouring Rain 667B Coat of Anticubism
- CodeForces - 667B Coat of Anticubism (数学几何规律)
- CodeForces 667B Coat of Anticubism(构造三角形)
- Codeforces Round #349 (Div. 2)-B. Coat of Anticubism(二分+贪心)
- Beijing Institute of Clothing set up a Heavenly Biography House - 2014 Moncler UK Loire Women Coat
- canada goose coat-086811
- A. Sereja and Coat Rack
- 【链表】URAL 1579 Coat Transportation
- I - Sereja and Coat Rack
- codeforce Sereja and Coat Rack(简单排序)
- CodeForces 368A Sereja and Coat Rack
- E文积累_20080402_the coat was a real buy
- Codeforces Round #215 (Div. 2) -A. Sereja and Coat Rack
- CF#215DIV2:A. Sereja and Coat Rack
- HTML 参考手册
- Boost.Interprocess使用手册翻译之十一:所有权的智能指针(Ownership smart pointers)
- 第一章、问答环节
- Hibernate缓存机制和MyBatis缓存机制
- HDU 5410 CRB and His Birthday(01背包+完全背包)
- Coat of Anticubism
- Node.js-入门五--path优化
- Excel 导入工具类
- 给 Android 开发者的 RxJava 详解
- 用MessageDigest提取String信息摘要也就是MD5值
- vector中size问题
- spark分布式安装 spark集群搭建 hadoop集群搭建
- 数据源与数据连接池的区别1
- doGet与doPost