Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author: wleung_bvg
Subtask 1
We can check all
tuples of
where
, check if
, and increment our total.
Time Complexity: 
Subtask 2
Suppose we had an array
such that
was equal to the number of indices
such that
and
. We can then iterate through all
tuples of
, and add
to our total. We can compute
using suffix sums.
Time Complexity: 
Subtask 3
Welcome to another wleung_bvg editorial. As usual, he still does not know how to do dynamic programming and is bad at grammar, so please continue to bear with him. Note that it is possible to solve this problem without dynamic programming.
Suppose we processed elements from left to right and maintained an array
with
equal to the number of increasing subsequences ending at or before index
with a length of
and a sum of
. Then for each element, we can add
to our total and update the
array appropriately. We can update the
array with the following recurrence:
![\text{dp}[i][y][z] = \begin{cases} \text{dp}[i - 1][y][z] + \text{dp}[i - 1][y - 1][z - A_i] & y \ge 1, z \ge A_i \\ \text{dp}[i - 1][y][z] & \text{otherwise} \end{cases}](//static.dmoj.ca/mathoid/b2770ce6cc1d9991b7d32e37628089e824b1f25e/svg)
The initial state of the
array is all elements equal to
with
. Note that we only need to consider
and
for this problem. While using this recurrence directly uses
memory, it is possible to reduce it to
.
Time Complexity: 
Comments