Cheerio Contest 1 S3 - Stock Trading

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Author:
Problem types

Ethan is an avid stock trader. In order to predict future stock prices, he performs technical analysis on stock charts by drawing trendlines. The chart is displayed as a grid with time on the x-axis and price on the y-axis. There are N points, where the ith point is (ti,pi), indicating that at time ti, the stock price was pi. Adjacent points are then connected to form a line graph. That is, point i is connected to points i1 and i+1.

The line connecting two points (ti,pi) and (tj,pj) where j>i is considered to be a trendline when all points in the range [i,j] are either all above/on the line or all below/on the line. Can you help Ethan find the number of different trendlines he can draw? Two trendlines are considered different if they start or end at different points.

Constraints

For all subtasks:

  • t1<t2<t3<<tN
Points Awarded N ti,pi
5 points 2N300 0ti,pi104
6 points 2N5000 0ti,pi104
4 points 2N5000 0ti,pi109

Input Specification

The first line contains one integer N.

The next N lines contain two integers ti and pi.

Output Specification

Output the number of different trendlines that could be drawn.

Sample Input

Copy
4
0 0
2 4
5 2
6 5

Sample Output

Copy
5

Explanation for Sample Output

Notice that the line connecting points 1 and 4 is not a trendline.


Comments

There are no comments at the moment.