Can someone share the editorial of Filling the Coffers: ANWCC02 question of CodeCharades 2019 contest.

If there are N vaults and M keys. There are at most N-M+1 ways to get the coins.

So for each way, apply fft to get dot product of two vectors and take maximum. In python, you can use `numpy.dot`

to get dot product of 2 vectors.

Why do you need FFT for this method? Also, I doubt this work in time for M close to N/2.

Assume m \le n,

For k \ge m-1,

â€¦which is the dot product of \langle a_{k-m+1}, a_{k-m+2}, \cdots, a_k \rangle and \langle b_{m-1}, b_{m-2}, \cdots, b_0 \rangle.

It should be straightforward to solve the problem now in \mathcal{O}((n+m) \log (n+m)) using FFT for polynomial multiplication.

Thanks for your explanation, but would you please elaborate third step with your solution

Do you mean P(x) \cdot Q(x)? That is just the product of polynomials P(x) and Q(x). My solution, if it helps: 22597272.

please try to explain mathematical part of that line.

Try to multiply two polynoms with coefficients from one array and from reversed another and consider result coefficients. It is standart case to use FFT.