answer:
1. I have seen something similar before, you can divide and conquer cdq
When l=r, there is still a remainder
So time is nmlogn space is mlogn
2. First of all, we can dp show the number of solutions for j
Let g[i][j] indicate that i cannot be selected, and indicate the number of options for j
Consider how to transfer
g[i][j+w[i]]=f[i][j+w[i]]-g[i][j]
This means that the number of solutions for j+w[i] can be calculated from the total number of solutions - the number of solutions with i
This is nm