Charlotte is writing a news article and needs to take a photo containing people, with the
th person having a height of
. People will be arranged into
rows, with
people on
each row. A person will be visible in the photo if they are in the
first row or if their height is strictly greater than everyone in earlier rows that are from the same column.
What is the maximum number of people that can be visible in the photo?
Constraints
Subtask 1 [20%]
Subtask 2 [20%]
Subtask 3 [60%]
No additional constraints.
Input Specification
The first line of input contains space separated integers,
and
, representing the number of rows and the number of columns respectively.
The second line of input contains space separated integers,
, representing the height of each person.
Output Specification
Output integer, the maximum number of people that can be visible in the photo.
Sample Input 1
2 3
2 2 2 2 1 1
Sample Output 1
5
Explanation for Sample 1
One possible optimal arrangement is shown below. Everyone except the second person in the second row is visible.
1 2 1
2 2 2
Sample Input 2
3 2
1 1 1 1 1 1
Sample Output 2
2
Explanation for Sample 2
No matter how we arrange them, only the people in the first row are visible.
Comments