A. Patrick and shopping
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 anda d2 meter long R Oad between he house and the second shop. Also, there is a road of length D3 directly connecting these. Help Patrick calculate the minimum distance, 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.
- D 1 is the length of the path connecting Patrick 's house and the first shop;
- D 2 is the length of the path connecting Patrick 's house and the second shop;
- D 3 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 Test (s)
input
10 20 30
Output
60
input
1 1 5
Output
4
Note
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.
Test Instructions : let you go from the middle of the house after a A, a, and back to the original point, the minimum distance is how much
The following:
///1085422276#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_backinline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){ if(ch=='-') f=-1; ch=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar (); }returnx*F;}//****************************************Const intn=100000+ -;#defineMAXN 100000+5intMain () {ll a=read (), B=read (), c=read (); ll ans=min (A *2+2*c,c*2+b*2); cout<<min (min (A *2+b*2, ans), a+b+c) <<Endl; return 0;}
Code
Codeforces Round #332 (Div. 2) A. Patrick and shopping water