Casting
InterviewTime limit1sMemory limit1024 MB
Given counts of tall, blue-eyed, and blonde actors, find the maximum or minimum possible number who have all three traits.
- Level
Medium4 of 10
- Topics
- Math, Combinatorics, Implementation, Greedy
- Solved
- No attempts yet
Problem
A theater employs actors. Among them, are tall, have blue eyes, and are blonde. The lead role in a new production requires just one performer: tall, blue-eyed, and blonde. To plan time for interviews with each such actor in the troupe, the director needs to know the maximum or the minimum number of actors in the theater who suit this role.
Write a program casting that determines the maximum or the minimum number of actors the director must talk to.
Input
The first line of the standard input contains a single integer that specifies whether the maximum or the minimum number of actors is to be found. This number can take the following values:
- if the minimum number of actors is to be determined;
- if the maximum number of actors is to be determined.
The second line of the standard input contains four integers , , , . The numbers are separated by a single space.
Output
On a single line of the standard output, the program must print one integer: the minimum or the maximum (depending on the input data) number of actors who can be candidates for the lead role.
Constraints
Hint
Explanation of sample 1: Since the tall actors number 3 in total, more than 3 people cannot go to an interview.
Explanation of sample 2: All actors are blonde, and all but 1 have blue eyes. Then among the three tall actors, at least two have blue eyes (and naturally, they are blonde). Therefore, at least two actors suit the lead role in the new production.