[BOJ 7119] The Magician

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 128M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

The circus magician Tâlrîts Vakars shows magic tricks. In his demonstrations he uses only:</p>

baloons (), doves (), rabbits () and poodels ().

Tâlrîts can carry out only the following tricks: (baloons and animals in the direction shown by the arrow are converted to different animals):

  1.  +  +   
  2.  +  +   
  3.  +  +  

Your task is to write a program that for the input number of baloons, doves, rabbits and poodels computes the maximum possible number of rabbits that Tâlrîts can obtain and the least number of tricks required to do this.

입력 형식

The values of non-negative integer numbers b (number of baloons, b ≤ 150), d (number of doves, d ≤ 150), t (number of rabbits, t ≤ 150) and p (number of poodels, p ≤ 150) are input from the keyboard. It is also known that b + d + t + p ≤ 250.

출력 형식

The maximum possible number of rabbits that Tâlrîts can obtain must be displayed on the screen, as well as (separated by a space symbol) the minimal number of tricks that is required to obtain this number of rabbits.

예제 입력 1

9 17 1 3

예제 출력 1

10 3

예제 입력 2

3 0 2 2

예제 출력 2

4 2

Comments

There are no comments at the moment.