Hosting Contests
InterviewTime limit2sMemory limit512 MB
Given counts of five problem groups, each usable at one of its allowed difficulty slots, find the maximum number of easy-medium-hard contests.
- Level
Medium5 of 10
- Topics
- Greedy, Binary search
- Solved
- No attempts yet
Problem
Hyeonjong likes holding programming contests. He has written a great many problems, and now he wants to know how many contests he can hold with them.
One contest consists of three problems: one easy problem, one medium problem, and one hard problem. All three must be on hand before a contest can be held.
Hyeonjong sorted the problems he has written into the following five difficulty groups.
- problems can be used only as an easy problem.
- problems can be used as an easy problem or as a medium problem.
- problems can be used only as a medium problem.
- problems can be used as a medium problem or as a hard problem.
- problems can be used only as a hard problem.
Each problem can be used in one contest only, and at one difficulty only.
Write a program that finds the maximum number of contests Hyeonjong can hold.
Input
The first line contains , , , , , separated by spaces. ()
Output
Print on the first line the maximum number of contests Hyeonjong can hold.