667B.md (2756B)
1 Source: https://codeforces.com/problemset/problem/667/B 2 3 B. Coat of Anticubism 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21  22 23 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. 24 25 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. 26 27 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 *l**i*. 28 29 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 . 30 31 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. 32 33 Help sculptor! 34 35 Input 36 37 The first line contains an integer *n* (3 ≤ *n* ≤ 105) — a number of rod-blanks. 38 39 The second line contains *n* integers *l**i* (1 ≤ *l**i* ≤ 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. 40 41 Output 42 43 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. 44 45 Examples 46 47 Input 48 49 ``` 50 3 51 1 2 1 52 ``` 53 54 Output 55 56 ``` 57 1 58 ``` 59 60 Input 61 62 ``` 63 5 64 20 4 3 2 1 65 ``` 66 67 Output 68 69 ``` 70 11 71 ``` 72 73 Note 74 75 In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. 76 77 In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.