Microwave
InterviewTime limit2sMemory limit512 MB
Given a start temperature below target, compute total heating time using per-degree rates for frozen and unfrozen states plus a fixed thawing time.
- Level
Easy2 of 10
- Topics
- Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
To prepare a meal, JOI wants to heat a piece of meat from °C to °C in a microwave. The meat is frozen when its temperature is below 0°C and not frozen when it is above 0°C. When the temperature is exactly 0°C, the meat may be either frozen or not frozen.
JOI assumes that the meat heats up according to the rules below and uses them to estimate how long the heating takes.
- While the meat is frozen and its temperature is below 0°C, the temperature rises by 1°C every seconds.
- While the meat is frozen and its temperature is exactly 0°C, thawing it into the not frozen state takes seconds.
- While the meat is not frozen, the temperature rises by 1°C every seconds.
Using these rules, find how many seconds it takes to heat the meat to °C.
Input
The input has five lines, each containing one integer.
- The first line contains the initial temperature of the meat. is between and inclusive and is not 0.
- The second line contains the target temperature . is between and inclusive and is greater than .
- The third line contains , the time needed to raise the temperature of frozen meat by 1°C.
- The fourth line contains , the time needed to thaw frozen meat.
- The fifth line contains , the time needed to raise the temperature of meat that is not frozen by 1°C.
, , and are each between and inclusive.
Output
Print on one line the time in seconds needed to heat the meat to °C.
Hint
In sample 1, the meat starts frozen at °C. The time is made up as follows.
- Heating from °C to 0°C takes seconds.
- Thawing the meat at 0°C takes 10 seconds.
- Heating from 0°C to 20°C takes seconds.
The total is 120 seconds.
In sample 2, the meat is not frozen at the start, so heating it from 35°C to 92°C takes 627 seconds.