#K71122. Longest Non-Decreasing Subsequence
Longest Non-Decreasing Subsequence
Longest Non-Decreasing Subsequence
Given an integer n and a sequence of n integers, your task is to determine the length of the longest non-decreasing subsequence that can be formed from the sequence.
A non-decreasing subsequence is defined such that for any two consecutive elements \(a_i\) and \(a_j\) in the subsequence where \(i < j\), it holds that \(a_i \le a_j\). Note that the subsequence is not required to be contiguous in the original sequence.
For example, if the input sequence is [10, 22, 9, 33, 21, 50, 41]
, one of the longest non-decreasing subsequences is [10, 22, 33, 50]
with a length of 4.
inputFormat
The input is read from standard input (stdin) and consists of two parts:
- An integer
n
representing the length of the sequence. n
space-separated integers that form the sequence.
If n = 0
, the sequence will be empty.
outputFormat
Output the length of the longest non-decreasing subsequence. The result should be printed to standard output (stdout).
## sample7
10 22 9 33 21 50 41
4
</p>