#P14360. [CSP-J 2025] 多边形
[CSP-J 2025] 多边形
Problem Description
Little R likes playing with sticks. Little R has sticks, and the length of the -th stick () is .
Little X wants Little R to choose several sticks from these sticks and connect them end to end in any order to form a polygon. Little R does not know the condition for sticks to form a polygon, so Little X told him directly: for sticks with lengths , these sticks can form a polygon if and only if and the sum of the lengths of all sticks is greater than twice the maximum length among all sticks, that is, .
Since Little R now knows the condition for sticks to form a polygon, Little X asks a harder question: how many ways are there to choose sticks such that the chosen sticks can form a polygon? You need to help Little R compute the number of ways to choose sticks such that the chosen sticks can form a polygon. Two ways are different if and only if the sets of indices of the chosen sticks are different, that is, there exists some such that one way chooses the -th stick but the other way does not. Since the answer may be large, you only need to compute the answer modulo .
Input Format
The first line of the input contains one positive integer , which is the number of Little R's sticks.
The second line of the input contains positive integers , which are the lengths of Little R's sticks.
Output Format
Output one line with a non-negative integer, which is the number of ways for Little R to choose sticks such that the chosen sticks can form a polygon, modulo .
5
1 2 3 4 5
9
5
2 2 3 8 10
6
Hint
Sample 1 Explanation
There are the following ways to choose sticks such that the chosen sticks can form a polygon:
- Choose the 2nd, 3rd and 4th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 2nd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 3rd and 4th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 3rd and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is .
Sample 2 Explanation
There are the following ways to choose sticks such that the chosen sticks can form a polygon:
- Choose the 1st, 2nd and 3rd sticks. The sum of lengths is , and the maximum length is ;
- Choose the 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is ;
- Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is , and the maximum length is .
Sample 3
See and in the contestant's directory.
This sample satisfies the constraints of test cases .
Sample 4
See and in the contestant's directory.
This sample satisfies the constraints of test cases .
Subtasks
For all testdata, it is guaranteed that:
- ;
- For all , .
::cute-table{tuack}
| Test case | ||
|---|---|---|
| ^ | ||
| ^ | ||
| ^ | ||
| ^ |
Translated by QwenWork