A. Patrick and Shopping
time limit per test
memory limit per test
input
output
d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3
Patrick always starts at his 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 is to minimize the total distance traveled.
Input
d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths.
- d1
- d2
- d3
Output
Print the minimum distance that Patrick will have 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 picture in the problem statement. One of the optimal routes is: house
first shop
second shop
house. In the second sample one of the optimal routes is: house
first shop
house
second shop
house.
#include <bits/stdc++.h>
using namespace std;
__int64 a[4];
int main()
{
__int64 aa,b,c;
scanf("%I64d%I64d%I64d",&aa,&b,&c);
a[0]=2*(aa+b);
a[1]=aa+b+c;
a[2]=2*aa+2*c;
a[3]=2*b+2*c;
sort(a,a+4);
printf("%I64d\n",a[0]);
return 0;
}