Use the function#920

Use the function (Editorial)

Algorithm Analysis

Define the minimum and maximum functions of two numbers. With their help, we will calculate the required expression.

Algorithm Implementation

Define the minimum min and maximum max functions of two numbers.

double min(double x, double y)
{
    return (x < y) ? x : y;
}

double max(double x, double y)
{
    return (x > y) ? x : y;
}

The main part of the program. We read the input data. Calculate and output the answer.

scanf("%lf %lf %lf",&x,&y,&z);
res = min(min(max(x,y),max(y,z)),x+y+z);
printf("%.2lf\n",res);

Java Implementation

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        con.useLocale(Locale.US);
        double x = con.nextDouble();
        double y = con.nextDouble();
        double z = con.nextDouble();

        double res = Math.min(Math.min(Math.max(x, y), Math.max(y, z)), x + y + z);
        System.out.println(res);
        con.close();
    }
}

Java Implementation – Custom Functions

import java.util.*;

public class Main
{
    public static double min(double x, double y)
    {
        return (x < y) ? x : y;
    }

    public static double max(double x, double y)
    {
        return (x > y) ? x : y;
    }

    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        double x = con.nextDouble();
        double y = con.nextDouble();
        double z = con.nextDouble();

        double res = min(min(max(x, y), max(y, z)), x + y + z);
        System.out.println(res);
        con.close();
    }
}

Python Implementation

x, y, z = map(float, input().split())
res = min(min(max(x, y), max(y, z)), x + y + z)
print(res)