WOSS Dual Olympiad 2022 J2: Counting Christmas Trees

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

You have gone to visit a plantation of Christmas trees before the holidays! The plantation you have visited is quite unique, as it consists of one row of N Christmas trees, numbered from 1 to N. Each of them has a height value, with the ith tree being assigned a height of h_i.

You are interested in finding patterns within the trees. Therefore, your job is to create a program that will output the length of the longest contiguous group of trees strictly increasing in height and the length of the longest contiguous group of trees strictly decreasing in height. The same tree(s) can be included in the two different contiguous groups.

Constraints

2 \le N \le 2\,000

1 \le h_i \le 200

Input Specification

The first line consists of a single integer, N, representing the number of Christmas trees.

The second line contains N space-separated integers, with the ith integer on the second line representing the value h_i, or the height of the ith tree.

Output Specification

The output should consist of two lines: the first line should contain a single integer, giving the length of the longest contiguous group of trees that are strictly increasing in height, and the second line should also contain a single integer, giving the length of the longest contiguous group of trees that are strictly decreasing in height.

Sample Input 1

4
1 3 4 2

Sample Output 1

3
2

Explanation of Sample 1

The longest contiguous group of strictly increasing tree heights is [1, 3, 4], which has a length of 3. The longest contiguous group of strictly decreasing tree heights is [4, 2], which has a length of 2.

Sample Input 2

10
2 1 4 6 8 2 9 5 2 3

Sample Output 2

4
3

Explanation of Sample 2

The longest contiguous group of strictly increasing tree heights is [1, 4, 6, 8], which has a length of 4. The longest contiguous group of strictly decreasing tree heights is [9, 5, 2], which has a length of 3.


Comments