Patrick and shopping (water problem)

Source: Internet
Author: User
I-patrick and shopping Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64D &%i64u Submit Status

Description

Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in both stores located near he house. There is a D1 meter long road between he house and the first shop and a D2 meter long road between he house and the Seco nd shop. Also, there is a road of length D3 directly connecting these. Help Patrick calculate the minimum distance this he needs to walk in order to go to both shops and return to his house.

Patrick always starts at he house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn ' t mind visiting the same shop or passing the same road multiple times. The only goal are to minimize the total distance traveled.

Input

The first line of the input contains three integers d1, D2, D3 (1≤d1, D2, d3≤108)-the lengths of the paths. D1 is the length of the path connecting Patrick's house and the first shop; D2 is the length of the path connecting Patrick's house and the second shop; D3 is the length of the path connecting both shops.

Output

Print the minimum distance that Patrick would has to walk in order to visit both shops and return to his house.

Sample Input Input

10 20 30
Output
60
Input
1 1 5
Output
4

Hint

The first sample is shown on the problem statement. One of the optimal routes Is:house first shop second.

In the second, sample one of the optimal routes Is:house first shop house second.


At first, we must go directly to a shop, so choose the nearest store to go first. Then go to another shop on the way home is only 3 left, compared to the smallest.

#include <stdio.h>
#include <algorithm>
using namespace std;
int main ()
{
    long long a,b,c;
    scanf ("%lld%lld%lld", &a,&b,&c);
    if (a>b)
    {
        long long tmp;
        Tmp=a;
        a=b;
        b=tmp;
    }
    Long Long dis1=2* (a+b), dis2=a+b+c,dis3=2* (a+c);
    printf ("%lld\n", Min (min (dis1,dis2), dis3));
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.