Codeforces 581A Vasya the Hipster Solution & Explanation

Difficulty : 800

Problem Description

One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn’t want to wash them.

Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he’s got.

Can you help him?

Input

The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya’s got.

Output

Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he’s got.

Keep in mind that at the end of the day Vasya throws away the socks that he’s been wearing on that day.

Examples

Input3 1
Output1 1
Input2 3
Output2 0
Input7 3
Output3 2

Note

In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.


Solution

Vasya can wear fashionable and different colored socks for a maximum of “min(a, b)” days.

After that, he can continue wearing the remaining socks for “(max(a, b) – min(a, b)) / 2” days until he runs out of socks or can no longer make a complete pair from the remaining socks.

C# Solution

Solution1

string[] arr = Console.ReadLine().Split(" ");
int a = int.Parse(arr[0]);
int b = int.Parse(arr[1]);

if(a==b){
    Console.WriteLine($"{a} 0");
}
else{
    int tmp = 0;
    if(a>b){
        tmp = (a-b)/2;
        Console.WriteLine($"{b} {tmp}");
    }
    else{   //b>a
        tmp = (b-a)/2;
        Console.WriteLine($"{a} {tmp}");
    }
}

Java Solution

Solution1

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] arr = scanner.nextLine().split(" ");
        int a = Integer.parseInt(arr[0]);
        int b = Integer.parseInt(arr[1]);
        
        if(a==b){
            System.out.println(a + " 0");
        }
        else{
            int tmp = 0;
            if(a>b){
                tmp = (a-b)/2;
                System.out.println(b + " " + tmp);
            }
            else{   //b>a
                tmp = (b-a)/2;
                System.out.println(a + " " + tmp);
            }
        }
    }
}

Conclusion

I usually wear socks of the same color and cannot relate to Vasya’s fashion sense of wearing different colored socks…

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 581A – Codeforces

Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *