Find the maximum number of possible(subject,student)pairs for the given credit limits and subject credit requirements.
In a university, there is a certain system of credits. Each of student is given a ‘credit limit’ which specifies the maximum credits of a subject they can take. A student can take any number of subjects which are under his/her credit limit.
There are N students and K subjects.Each subject has a specified number of credits .when student choose a subject ,it becomes a (student,subject)pair.
Find the maximum number of possible(subject,student)pairs for the given credit limits and subject credit requirements.
Input1:K denoting the number of subjects
Input2:An array of K elements each denoting the credits to take a subject
Input3:N denoting the number of students
Input4:An array of N elements each denoting the credit limit of a student.
Output:Your should return the maximumnumber of possible required pairs.
Example1:
Inpput1:3
Input2:{44,45,56,39,2,6,17,75}
Input3:1
Input4:{54}
Output:6
Solution
public int maximumPairs(int Input1, int[] Input2, int Input3, int[] Input4) {
int max = 0;
for (int i = 0; i < Input4.length; i++) {
int count = 0;
// https://sauravhathi.github.io/lpu-cse
for (int j = 0; j < Input2.length; j++) {
if (Input2[j] <= Input4[i]) {
count++;
}
}
if (count > max) {
max = count;
}
}
return max;
}
Happy Learning – If you require any further information, feel free to contact me.