I was asked this in an OA but wasn't able to come up with a solution. Any pointers will be helpful.
There are N students in a class who are to be seated in a row of N length. Each student likes different seats and ith student gets A[i][j] comfort while sitting on jth seat.
The students also want to make sure they can see the blackboard (placed at the front of the class) clearly and hence do not want more than p students whose height is greater than their own to sit in front of them. A seating arrangement is said to be valid if the above condition is met.
Your task is to determine the maximum possible comfort students can get with a valid seating arrangement in which every student can see things written on the blackboard.
Examples:
Sample 1:
N is number of rows and columns in A
A is a 2D array - denotes the comfort values of seats
H is the height array
P is the maximum number of higher height students that can sit in front of any student
Input:
N=2,
A =
[[2,3],
[1,4]]
H = [1,2]
P = 0
Output: 6
As students should be sitting in ascending order of their heights, so 1st student should sit on seat 1 and 2nd student should sit on seat 2. So the answer is 2+4 = 6.
Sample2:
N = 2
A = [
[2,5]
[4,1]]
H = [1,2]
P = 0
Output = 3
As students should sit in ascending order of their heights, so 1st student should sit on seat1 and 2nd student on seat 2. So, answer is 2+1 = 3
Sample3:
N = 2
A = [
[2,3]
[1,4]]
H = [1,2]
P = 1
Output = 6
Here, best arrangement is 1st student sits on seat 1 and 2nd student on seat 2. This gives a maximum comfort of 2+4=6.