#P5606. 小 K 与毕业旅行
小 K 与毕业旅行
Background
Xiao K is a high school student who has just finished the college entrance exam. He is planning a graduation trip, but some details are troubling him. Please help him!
Problem Description
There are attractions in the graduation trip plan. Everyone will visit these attractions in some order, and each attraction will be visited exactly once.
Each attraction has a coordinate . Taking a ride from the attraction with coordinate to the attraction with coordinate will cause discomfort of . After getting off the vehicle each time, the discomfort is reset to (that is, discomfort does not accumulate). If the discomfort of any ride exceeds a certain constant , someone will get sick.
Xiao K wants to know how many visiting orders of all attractions make sure that no one gets sick throughout the whole trip. Output the answer modulo .
Input Format
The first line contains a positive integer and a non-negative integer .
The second line contains integers .
Output Format
Output one line containing one integer, the answer.
3 3
1 2 3
2
6 5
1 1 4 5 1 4
144
16 20
9 9 3 2 4 4 8 5 3 -1 -9 -1 -9 -8 -1 0
802901549
Hint
Sample Explanation
For sample , there are two valid orders: and .
Constraints
This problem has subtasks. You must pass all test points within a subtask to get the score for that subtask.
For all data, , .
| # | Score | ||
|---|---|---|---|
| 1 | No special restrictions | ||
| 2 | |||
| 3 | |||
| 4 | There are only three distinct , and | ||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | No special restrictions | ||
| 9 | |||
| 10 |
Translated by ChatGPT 5