#K60837. Maximizing Increasing Flowers
Maximizing Increasing Flowers
Maximizing Increasing Flowers
You are given N flowers, each with a specified height. Your task is to determine two values:
- The maximum number of flowers that can be arranged such that their heights form a strictly increasing sequence (i.e. the length of the longest strictly increasing subsequence).
- The minimum number of watering operations required. The watering operation is defined as follows: starting from the first flower, traverse the sequence and each time you encounter a flower whose height is not greater than the current flower's height, you perform a watering operation (which hypothetically resets its height to be as low as possible), then update the current height to that flower's height.
For instance, given 7 flowers with heights: 2, 3, 5, 1, 4, 6, 7, the longest strictly increasing subsequence has length 5 and exactly 2 watering operations are required.
Note: You should read the input from standard input (stdin) and write the output to standard output (stdout). If there are multiple test cases, process only one test case as described below.
inputFormat
The first line of input contains a single integer N representing the number of flowers. The second line contains N space-separated integers describing the heights of the flowers.
Constraints:
- 1 ≤ N ≤ 105
- Each height is an integer in a reasonable range.
outputFormat
Output two space-separated integers on a single line: the length of the longest strictly increasing subsequence among the flower heights, and the minimum number of watering operations needed as described.
## sample7
2 3 5 1 4 6 7
5 2