OTHS Coding Competition 4 P3 - Photo

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Java 4.0s
Python 4.0s
Memory limit: 512M
Java 1G
Python 1G

Author:
Problem type

Charlotte is writing a news article and needs to take a photo containing R \times C people, with the ith person having a height of A_i. People will be arranged into R rows, with C 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

1 \le R, C \le 1000

1 \le A_i \le 10^9

Subtask 1 [20%]

C = 1

Subtask 2 [20%]

1 \le A_i \le 2

Subtask 3 [60%]

No additional constraints.

Input Specification

The first line of input contains 2 space separated integers, R and C, representing the number of rows and the number of columns respectively.

The second line of input contains R \times C space separated integers, A_i, representing the height of each person.

Output Specification

Output 1 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

There are no comments at the moment.