33OJ
登录 注册

#P14360. [CSP-J 2025] 多边形

    ID: 16148 远端评测题 1000ms 512MiB 尝试: 59 已通过: 13 显示难度普及 上传者: 标签>动态规划 DP2025O2优化背包 DPCSP-J 入门级

[CSP-J 2025] 多边形

Problem Description

Little R likes playing with sticks. Little R has nn sticks, and the length of the ii-th stick (1≤i≤n1 \leq i \leq n) is aia_i.

Little X wants Little R to choose several sticks from these nn 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 mm sticks with lengths l1,l2,…,lml_1, l_2, \dots, l_m, these mm sticks can form a polygon if and only if m≥3m \geq 3 and the sum of the lengths of all sticks is greater than twice the maximum length among all sticks, that is, ∑i=1mli>2×max⁡i=1mli\sum_{i=1}^{m} l_i > 2 \times \max_{i=1}^{m} l_i.

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 1≤i≤n1 \leq i \leq n such that one way chooses the ii-th stick but the other way does not. Since the answer may be large, you only need to compute the answer modulo 998,244,353998,244,353.

Input Format

The first line of the input contains one positive integer nn, which is the number of Little R's sticks.

The second line of the input contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n, 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 998,244,353998,244,353.

5
1 2 3 4 5
9
5
2 2 3 8 10
6

Hint

Sample 1 Explanation

There are the following 99 ways to choose sticks such that the chosen sticks can form a polygon:

  1. Choose the 2nd, 3rd and 4th sticks. The sum of lengths is 2+3+4=92 + 3 + 4 = 9, and the maximum length is 44;
  2. Choose the 2nd, 4th and 5th sticks. The sum of lengths is 2+4+5=112 + 4 + 5 = 11, and the maximum length is 55;
  3. Choose the 3rd, 4th and 5th sticks. The sum of lengths is 3+4+5=123 + 4 + 5 = 12, and the maximum length is 55;
  4. Choose the 1st, 2nd, 3rd and 4th sticks. The sum of lengths is 1+2+3+4=101 + 2 + 3 + 4 = 10, and the maximum length is 44;
  5. Choose the 1st, 2nd, 3rd and 5th sticks. The sum of lengths is 1+2+3+5=111 + 2 + 3 + 5 = 11, and the maximum length is 55;
  6. Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is 1+2+4+5=121 + 2 + 4 + 5 = 12, and the maximum length is 55;
  7. Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is 1+3+4+5=131 + 3 + 4 + 5 = 13, and the maximum length is 55;
  8. Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is 2+3+4+5=142 + 3 + 4 + 5 = 14, and the maximum length is 55;
  9. Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is 1+2+3+4+5=151 + 2 + 3 + 4 + 5 = 15, and the maximum length is 55.

Sample 2 Explanation

There are the following 66 ways to choose sticks such that the chosen sticks can form a polygon:

  1. Choose the 1st, 2nd and 3rd sticks. The sum of lengths is 2+2+3=72 + 2 + 3 = 7, and the maximum length is 33;
  2. Choose the 3rd, 4th and 5th sticks. The sum of lengths is 3+8+10=213 + 8 + 10 = 21, and the maximum length is 1010;
  3. Choose the 1st, 2nd, 4th and 5th sticks. The sum of lengths is 2+2+8+10=222 + 2 + 8 + 10 = 22, and the maximum length is 1010;
  4. Choose the 1st, 3rd, 4th and 5th sticks. The sum of lengths is 2+3+8+10=232 + 3 + 8 + 10 = 23, and the maximum length is 1010;
  5. Choose the 2nd, 3rd, 4th and 5th sticks. The sum of lengths is 2+3+8+10=232 + 3 + 8 + 10 = 23, and the maximum length is 1010;
  6. Choose the 1st, 2nd, 3rd, 4th and 5th sticks. The sum of lengths is 2+2+3+8+10=252 + 2 + 3 + 8 + 10 = 25, and the maximum length is 1010.

Sample 3

See polygon/polygon3.in\textit{\textbf{polygon/polygon3.in}} and polygon/polygon3.ans\textit{\textbf{polygon/polygon3.ans}} in the contestant's directory.

This sample satisfies the constraints of test cases 7∼107 \sim 10.

Sample 4

See polygon/polygon4.in\textit{\textbf{polygon/polygon4.in}} and polygon/polygon4.ans\textit{\textbf{polygon/polygon4.ans}} in the contestant's directory.

This sample satisfies the constraints of test cases 11∼1411 \sim 14.

Subtasks

For all testdata, it is guaranteed that:

  • 3≤n≤5 0003 \leq n \leq 5\,000;
  • For all 1≤i≤n1 \leq i \leq n, 1≤ai≤5 0001 \leq a_i \leq 5\,000.

::cute-table{tuack}

Test case n≤n \leq max⁡i=1nai≤\max_{i=1}^{n} a_i \leq
1∼31 \sim 3 33 1010
4∼64 \sim 6 1010 10210^2
7∼107 \sim 10 2020 ^
11∼1411 \sim 14 500500
15∼1715 \sim 17 ^ 11
18∼2018 \sim 20 5 0005\,000 ^
21∼2521 \sim 25 ^ 5 0005\,000

Translated by QwenWork