#P3926. Heating the Jelly
Heating the Jelly
Heating the Jelly
SOL and SOL-kun love their konjac jelly. The jelly is normally stored at a degrees in the refrigerator, but when taken out it's too cold and needs heating. SOL plans to use a magical electric stove that heats the jelly according to the following rules:
- If the jelly's temperature is less than c, it increases by 1 unit every p time units.
- Once the jelly reaches exactly c degrees, it must undergo a defrosting process that lasts q time units. (During this phase change, the temperature does not increase.)
- After the defrosting is complete, the jelly heats further, increasing by 1 unit every r time units.
Given an initial temperature of a and a total heating time of x time units, compute the final temperature of the jelly. Note that if the time remaining is not enough to complete a full heating interval (p or r) or the full defrost period (q), then no temperature change occurs during that fragment of time.
The formulas used are:
- For temperature increase before defrost: If t < c, then additional temperature increment = \(\left\lfloor \frac{\text{time}}{p} \right\rfloor\).
- For temperature increase after defrost: Additional increment = \(\left\lfloor \frac{\text{remaining time after defrost}}{r} \right\rfloor\).
Output the final temperature as an integer (rounding down any fractional increase).
inputFormat
The input consists of a single line containing six space-separated integers:
- a: the initial temperature (in degrees).
- c: the temperature at which defrosting is required.
- p: the time units required to raise the temperature by 1 degree when the temperature is below c.
- q: the time units required for the defrosting process at exactly c degrees.
- r: the time units required to raise the temperature by 1 degree after defrosting.
- x: the total heating time in time units.
outputFormat
Output a single integer, the final temperature of the jelly after x time units of heating.
sample
5 10 2 3 3 20
12