#P8145. [JRKSJ R4] kth
[JRKSJ R4] kth
Background
Always remember that you are a human, not an animal.
Before eating corn-and-tomato stewed goat meat, you need to answer a question.
Problem Description
Given , call an integer sequence “valid” (denote it by ) if:
- The length of is .
- .
- .
Given a permutation of , define the “corresponding sequence” of an integer sequence as follows: has the same length as . Let the length be . Then .
Given , among the corresponding sequences of all distinct valid integer sequences, find the sum of all elements of the -th smallest corresponding sequence in lexicographical order, modulo .
If the -th smallest corresponding sequence does not exist, output .
Input Format
The first line contains three integers .
The second line contains integers representing .
Output Format
Output one integer, representing the answer.
10 6 3
5 7 4 3 6 2 10 8 9 1
38
2 5 2
1 2
8
2 114514 1
2 1
171771
3 1000000000000000000 3
2 1 3
2065039361
Hint
The input file of this problem is large, so please use an appropriate input method.
Sample Explanation
For sample , among the corresponding sequences of all distinct valid integer sequences, the three smallest in lexicographical order are:
So the answer is .
For sample , among the corresponding sequences of all distinct valid integer sequences, the two smallest in lexicographical order are:
So the answer is .
Constraints
| Score | ||||
|---|---|---|---|---|
For of the data, , , .
Special Scoring Method
This problem uses subtask dependencies, as follows:
- For subtasks , you only need to solve subtask correctly to get the score of subtask .
- For subtasks , you need to solve all subtasks correctly to get the score of subtask .
Translated by ChatGPT 5