#K90667. Visible Plants from the Left
Visible Plants from the Left
Visible Plants from the Left
You are given a field represented as a grid of integers, where each integer denotes the height of a plant. The plants are arranged in rows. Your task is to determine the total number of plants visible when the field is viewed from the left side.
For each row, a plant is visible if and only if its height is strictly greater than all the plants to its left in that row. In other words, for a row represented as \(a_1, a_2, \dots, a_n\), the \(i\)-th plant is visible if \[ a_i > \max\{a_1, a_2, \dots, a_{i-1}\}, \] with the convention that \(\max(\emptyset) = -\infty\). The final answer is the sum of the visible plant counts for all rows.
Example:
- Row: [3, 5, 4] → Visible plants: 3 and 5 (count = 2)
- Row: [2, 4, 7] → Visible plants: 2, 4, and 7 (count = 3)
- Overall count = 2 + 3 = 5.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer \(R\), the number of rows in the field.
- Each of the next \(R\) lines contains a sequence of space-separated integers, representing the heights of the plants in that row.
Note: The rows may have different lengths.
outputFormat
Output a single integer to standard output (stdout) representing the total number of plants visible from the left side of the field.
## sample3
3 5 4
2 4 7
6 1 3
6