#P3114. Visible Cows

    ID: 16372 Type: Default 1000ms 256MiB

Visible Cows

Visible Cows

Farmer John has N cows (where \(1 \le N \le 50000\)) competing in a foot race. Each cow is depicted as a unit-length horizontal segment. At time \(t = 0\), a cow is given by the coordinates of its left endpoint \((x, y)\). Thus, a cow at \((-3,6)\) initially occupies the segment from \((-3,6)\) to \((-2,6)\). Each cow moves to the right (the positive \(x\) direction) at a rate determined by an integer \(T\) which is the amount of time it takes to travel 1 unit. In other words, a cow’s speed is \(\frac{1}{T}\) units per time.

Farmer John, not pleased with the disruption, positions himself at \((0,0)\) and looks upward along the \(+y\) axis. As the race unfolds, he sees a cow if at any moment that cow is the first one encountered along his line of sight. More formally, during the race a cow is visible if there exists a time \(t\) such that:

[ \text{(i) The cow covers the vertical line at }x=0\quad \text{and} \quad \text{(ii) no cow with a smaller (y) (i.e. closer to Farmer John) is also covering }x=0\text{ at that time.} ]

For a cow with initial left coordinate \(x\) and time parameter \(T\), its segment moves so that at time \(t\) it covers \([x + \tfrac{t}{T},\; x+1 + \tfrac{t}{T}]\). Thus, the cow covers \(x=0\) for time values \(t\) in the interval

[ t \in \Bigl[ \max\bigl(0, -T(x+1)\bigr), ; -Tx \Bigr]. ]

Your task is to determine the number of cows that Farmer John can see during the race.

inputFormat

The first line contains a single integer \(N\) representing the number of cows. Each of the following \(N\) lines contains three space-separated integers: \(x\), \(y\), and \(T\) (in that order), where \(x\) is the initial \(x\)-coordinate of the cow's left endpoint, \(y\) is its \(y\)-coordinate, and \(T\) is the time it takes the cow to move 1 unit to the right. It is guaranteed that the race starts at time \(t = 0\) and that only cows which eventually cover the vertical line \(x=0\) are considered.

outputFormat

Output a single integer which is the number of cows that Farmer John sees at some point during the entire race.

sample

3
-2 1 3
-3 2 3
0 3 3
2