#P3270. [JLOI2016] 成绩比较

[JLOI2016] 成绩比较

Description

The G Department has NN students and MM required courses. The students are numbered by integers from 00 to N1N-1, and B Shen's number is 00. The MM required courses are numbered from 00 to M1M-1. In each required course, a student can earn an integer score from 11 to UiU_i inclusive.

If in every course A's score is less than or equal to B's score, then A is said to be dominated by B. According to B Shen, there are KK students whom he dominates (excluding himself), and the other NK1N-K-1 students are not dominated by him. D Shen has found B Shen's rank in each required course.

Here, rank means: if B Shen's rank in some course is RR, then exactly R1R-1 students have a score strictly greater than B Shen's score in that course, and exactly NRN-R students have a score less than or equal to B Shen's score in that course (excluding himself).

We need to count the number of possible score assignments for all students in all required courses that satisfy both B Shen's statement and the ranks found by D Shen. Two assignments are different if and only if there exists at least one student and one course where the assigned score differs.

You do not need to be as powerful as D Shen; just compute the answer modulo 109+710^9+7.

Input Format

  • The first line contains three positive integers N,M,KN, M, K, denoting the number of students in the G Department (including B Shen), the number of required courses, and the number of students dominated by B Shen.
  • The second line contains MM positive integers, the maximum score UiU_i of each course in order.
  • The third line contains MM positive integers, B Shen's rank RiR_i in each course in order.
  • It is guaranteed that there is at least one assignment that makes B Shen's statement hold.

Output Format

Output a single integer on one line, the number of valid assignments modulo 109+710^9+7.

3 2 1
2 2
1 2
10

Hint

Constraints: 1N1001 \leq N \leq 100, 1M1001 \leq M \leq 100, 1Ui1091 \leq U_i \leq 10^9, 1RiN1 \leq R_i \leq N.

Translated by ChatGPT 5