#P15870. 【MX-X26-T6】「Cfz Round 7」vivi

【MX-X26-T6】「Cfz Round 7」vivi

Background

こんな話など 忘れておくれ / Please forget stories like this.

言いたいことは 一つもないさ / There is not a single thing I want to say.

Problem Description

In a shop, there are nn "fishies" lined up in a row. The volume of the ii-th "fishy" is aia_i.

Yuki has a backpack with volume VV. She plans to consider the "fishies" from 11 to nn in order: if the current "fishy"'s volume is less than or equal to the remaining volume of the backpack, she puts this "fishy" into the backpack; otherwise, she does not. When a "fishy" with volume xx is put into the backpack, the remaining volume of the backpack decreases by xx.

Since Yuki is a magical girl, she can choose the initial volume V\boldsymbol{V} of the backpack to be any non-negative integer, but she will not change the backpack's volume while considering the "fishies".

Let sis_i denote the selection status of the ii-th "fishy". Specifically, if the ii-th "fishy" is put into the backpack then si=1s_i=1, otherwise si=0s_i=0. You need to compute how many different sequences ss can be generated by the strategy above.

Input Format

The first line contains an integer cc, indicating the subtask index of this test point. The samples satisfy c=0c=0.

The second line contains an integer nn.

The third line contains nn integers a1,…,ana_1,\dots,a_n.

Output Format

Output one line containing a non-negative integer, representing the number of different sequences ss that can be generated.

0
3
1 3 8
4
0
4
1 3 1 4
6
0
5
16 8 4 2 1
32
0
6
7 4 4 6 8 7
9

Hint

Sample 1 Explanation

  • When the initial backpack volume V=0V=0, s={0,0,0}s=\{0,0,0\}.
  • When the initial backpack volume V=2V=2, s={1,0,0}s=\{1,0,0\}.
  • When the initial backpack volume V=5V=5, s={1,1,0}s=\{1,1,0\}.
  • When the initial backpack volume V=23V=23, s={1,1,1}s=\{1,1,1\}.

It is easy to prove that when the initial backpack volume VV is any other non-negative integer, the generated ss must be one of these 44 sequences, so the answer is 44.

Sample 2 Explanation

  • When the initial backpack volume V=0V=0, s={0,0,0,0}s=\{0,0,0,0\}.
  • When the initial backpack volume V=1V=1, s={1,0,0,0}s=\{1,0,0,0\}.
  • When the initial backpack volume V=3V=3, s={1,0,1,0}s=\{1,0,1,0\}.
  • When the initial backpack volume V=4V=4, s={1,1,0,0}s=\{1,1,0,0\}.
  • When the initial backpack volume V=7V=7, s={1,1,1,0}s=\{1,1,1,0\}.
  • When the initial backpack volume V=10V=10, s={1,1,1,1}s=\{1,1,1,1\}.

It is easy to prove that when the initial backpack volume VV is any other non-negative integer, the generated ss must be one of these 66 sequences, so the answer is 66.

Constraints

For all testdata:

  • 1≤n≤2⋅1051 \le n \le 2\cdot10^5.
  • For all 1≤i≤n1 \le i \le n, 1≤ai≤1091 \le a_i \le 10^9.

This problem uses bundled tests.

  • Subtask 1 (7 points): n≤18n \le 18.
  • Subtask 2 (11 points): n≤100n \le 100; for all 1≤i≤n1 \le i \le n, ai≤100a_i \le 100.
  • Subtask 3 (8 points): n≤500n \le 500; for all 1≤i≤n1 \le i \le n, ai≤500a_i \le 500.
  • Subtask 4 (5 points): n≤500n \le 500.
  • Subtask 5 (12 points): n≤8⋅103n \le 8\cdot10^3; for all 1≤i≤n1 \le i \le n, ai≤8⋅103a_i \le 8\cdot10^3.
  • Subtask 6 (15 points): n≤8⋅103n \le 8\cdot10^3.
  • Subtask 7 (13 points): n≤8⋅104n \le 8\cdot 10^4.
  • Subtask 8 (12 points): the sequence aa is guaranteed to be non-increasing.
  • Subtask 9 (17 points): no special constraints.

Translated by ChatGPT 5