Lazy Misha#3867

Lazy Misha (Editorial)

Mishka chooses the task that will take the least time. Therefore, the answer is the smallest of the three numbers, that is, min(t_1, t_2, t_3).

Let's find the minimum by successive comparisons:

After these two checks, the variable contains the minimum of the three values.

The same result can be obtained more concisely with a nested call to the min function:

min(min(t_1, t_2), t_3)

In C++, the following notation also works:

min(\{t_1, t_2, t_3\})

Algorithm implementation

Read the input data.

scanf("%d %d %d",&t1,&t2,&t3);

Compute the minimum among t_1, t_2, t_3.

min = t1;
if (t2 < min) min = t2;
if (t3 < min) min = t3;

Print the answer.

printf("%d\n",min);

Java implementation

import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner con = new Scanner(System.in);
    int a = con.nextInt();
    int b = con.nextInt();
    int c = con.nextInt();

    int res = a;
    if (b < res) res = b;
    if (c < res) res = c;
    
    System.out.println(res);
    con.close();
  }
}   

Java implementation — Math.min

import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner con = new Scanner(System.in);
    int a = con.nextInt();
    int b = con.nextInt();
    int c = con.nextInt();
    
    System.out.println(Math.min(Math.min(a,b),c));
    con.close();
  }
}   

Python implementation

Read the input data.

t1, t2, t3 = map(int,input().split())

Compute the minimum among t_1, t_2, t_3.

res = min(t1, t2, t3)

Print the answer.

print(res)