Matching Mentors
Time limit1sMemory limit1024 MB
Count the ways to match students with mentors, each student and mentor used at most once, that maximize the minimum final skill across all students.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Sorting, Combinatorics
- Solved
- No attempts yet
Problem
There are students and mentors. You want to raise the skills of the students by matching them with mentors.
Student has skill , and mentor has leadership . You can match at most one mentor to each student, and each mentor can guide at most one student. A student may also be left without a mentor. When a mentor is matched to a student, that student's skill increases by the mentor's leadership.
Count the number of mentor matching methods that maximize the minimum skill among all students.
Input
The first line contains the number of students and the number of mentors , separated by a space.
The second line contains the skills of the students , separated by spaces.
The third line contains the leadership of the mentors , separated by spaces.
Output
Print the number of mentor matching methods that maximize the minimum skill of all students, modulo .