#K36387. Longest Non-Decreasing Subarray
Longest Non-Decreasing Subarray
Longest Non-Decreasing Subarray
Given the sales data for (n) consecutive days, find the longest contiguous subarray where the sales are non-decreasing. In other words, for every index (i) in the subarray (with (i > 0)), the condition (sales[i] \geq sales[i-1]) holds true. If there are multiple subarrays with the same maximum length, output the one that appears first.
Note: The subarray must be contiguous, and the answer should include both the length of the subarray and the subarray itself.
inputFormat
The input is given via standard input (stdin):
The first line contains an integer (n), the number of days. The second line contains (n) space-separated integers representing the sales figures for each day.
outputFormat
Output via standard output (stdout):
On the first line, print the length of the longest non-decreasing subarray. On the second line, print the elements of this subarray separated by a space.## sample
7
100 180 260 40 310 535 695
4
40 310 535 695
</p>