Choosing Clothes
Time limit1sMemory limit1024 MB
Given the counts of tops, jeans, sweatpants, light innerwear, and dark innerwear, find the maximum number of days Yura can wear clothes without washing any item.
- Level
Medium6 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Yura's closet has tops, bottoms, and innerwear items. Every day, Yura picks one top, one bottom, and one innerwear item from the closet and wears them. The same top cannot be worn two days in a row. The same bottom can be worn two days in a row, but not three days in a row.
The bottoms are jeans and sweatpants (). The innerwear is light-colored items and dark-colored items (). Because of dye transfer, jeans and light-colored innerwear cannot be worn on the same day.
A top or bottom worn for 5 days becomes dirty and must be washed before it is worn again. Innerwear becomes dirty after just one day of wear and must be washed before it is worn again. Every top, bottom, and innerwear item in the closet is unworn at the start. Find how many days Yura can wear clothes from the closet without washing any of them.
Input
The first line contains an integer .
The second line contains two integers and , separated by a space.
The third line contains two integers and , separated by a space.
Output
Print the answer to the problem.