A. Make a triangle!

Masha has three sticks of length aa, bb and cc centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.

What is the minimum number of minutes she needs to spend increasing the stick’s length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle’s sides (one stick for one side) and their endpoints should be located at triangle’s vertices.

Input
The only line contains tree integers aa, bb and cc (1≤a,b,c≤1001≤a,b,c≤100) — the lengths of sticks Masha possesses.

Output
Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.

Examples
inputCopy
3 4 5
outputCopy
0
inputCopy
2 5 3
outputCopy
1
inputCopy
100 10 10
outputCopy
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.

In the second example, Masha can’t make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 22 centimeter stick by one and after that form a triangle with sides 33, 33 and 55 centimeters.

In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.(看到了吗,一肚子坏水,变着法儿的误导你)

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int a[3];
    while(cin >> a[0] >> a[1] >> a[2])
    {
        sort(a, a + 3);
        if(a[0] + a[1] > a[2])
            cout << '0' << '\n';
        else
            cout << a[2] + 1 - a[1] - a[0] << '\n';
    }
    return 0;
}

全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
2025-12-16 15:40
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务