Futures Market Trends
Time limit2sMemory limit512 MB
Count subsegments of a price sequence whose average daily change is at least P times the standard deviation of the changes, both positive and negative.
- Level
Medium7 of 10
- Topics
- Math, Prefix sum, Brute force, Implementation
- Solved
- No attempts yet
Problem
Fedor wants to earn some extra money from oil futures. His analysis is based on trends and historical data of previous days.
A cost sequence of at least three distinct days forms a trend of power if the average cost change is at least times bigger than the standard deviation of cost changes.
Formally, the average cost change is . The standard deviation of cost changes is . The sequence forms a positive trend of power if , and a negative trend of power if .
We assume that if and then a positive trend of any power is formed. Similarly, if and then a negative trend of any power is formed. If then no trend is formed, even if .
To check his theory, Fedor needs to count the number of subsegments of historical data which form positive and negative trends of the given power. Can you help him?
Input
The first line contains an integer () and a real number (), the number of days in Fedor's historical data and the required trend power. is given with at most 9 digits after the decimal point.
The next line contains integers (). For each , is the cost of oil futures at the end of the -th day.
Output
Print two integers: the number of subsegments of historical data forming a positive and a negative trend of power , respectively. It's guaranteed that the answer would not change if one changes by no more than .
Note
The third example test case demonstrates the real prices of oil futures in April 2020 (in dollars, multiplied by 10 and rounded). Be careful with theories like the one Fedor made.