Time limit: 0.1s
Memory limit: 64MB
A lot of bugs from Bugland have invaded a wine cellar trough a magic portal. The wine cellar consists of rooms, each full with barrels of wine, and the room being infested with bugs.
The owners of the wine cellar have at their disposal insecticides of two types: sprays named AntiBug, which can remove bugs a day, and sprays named ZeroBugs, which can remove bugs a day. Every day, a spray is used in every room.
Given those details, what is the minimum number of days in which the barrels of wine are saved by eliminating all the bugs?
The first line will contain two numbers, and , on the second one and , and on the third numbers, the representing the number of bugs from the room.
The first line will contain the minimum number of days necessary to eliminate all the bugs.
Constraints and clarifications
- For tests worth 40 points: , and
- A spray can be used in a single room each day, and two sprays cannot be used in the same room because using different types of sprays simultaneously can cause serious damage to the wine, and multiple uses of the same type of spray do not amplify the effect.
5 2 3 1 5 3 4 8 7
After one day: (from rooms and , bugs will be eliminated and from rooms and , bug)
After two days: (from rooms and , bugs will be eliminated and from rooms and , bug)
After tree days: (from room , bugs will be eliminated, from room , bugs and from rooms and , bug)
After four days: (from room , bug will be eliminated)