Cold Shower
InterviewTime limit1sMemory limit1024 MB
Simulate the shower temperature for n seconds under the given update rule and sum the distances between each temperature and the comfortable temperature k.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Dohun lives alone and plans to take a shower over seconds.
Dohun's mysterious shower has a natural temperature change of each time seconds pass. Dohun cannot predict this pattern, so he adjusts the shower based on the previous temperature.
Dohun's comfortable temperature is given.
Let be the shower temperature after seconds. The temperature at time is given.
Dohun adjusts the shower temperature as follows.
- If at time , the water is too hot, so he sets .
- If at time , the water is too cold, so he sets .
- If at time , the water temperature is right, so he does not adjust it. That is, .
The discomfort index is the sum of the differences between the shower temperature and the comfortable temperature at every second, starting from second 1. In other words, the discomfort index is .
Find the discomfort index that Dohun feels.
Input
The first line contains three integers , , and , separated by spaces.
The second line contains integers , separated by spaces.
Output
Print Dohun's discomfort index.
Constraints