#P17026. [NWERC 2020] Atomic Energy

[NWERC 2020] Atomic Energy

Problem Description

The Next Wave Energy Research Club is looking at several atoms as potential energy sources, and has asked you to do some computations to see which are the most promising.

Although an atom is composed of various parts, for the purposes of this method only the number of neutrons in the atom is relevant (In fact, for this problem you might want to forget everything you thought you knew about chemistry.). In the method, a laser charge is fired at the atom, which then releases energy in a process formally called explodification. Exactly how this process proceeds depends on the number of neutrons kk:

  • If the atom contains knk \le n neutrons, it will be converted into aka_k joules of energy.

  • If the atom contains k>nk > n neutrons, it will decompose into two atoms with ii and jj neutrons respectively, satisfying i,j1i,j \ge 1 and i+j=ki+j=k. These two atoms will then themselves explodificate.

When an atom with kk neutrons is explodificated, the total energy that is released depends on the exact sequence of decompositions that occurs in the explodification process. Modern physics is not powerful enough to predict exactly how an atom will decompose---however, for explodification to be a reliable energy source, we need to know the minimum amount of energy that it can release upon explodification. You have been tasked with computing this quantity.

Input Format

The input consists of:

  • One line with two integers nn and qq (1n1001 \le n \le 100, 1q1051 \le q \le 10^5), the neutron threshold and the number of experiments.
  • One line with nn integers a1,,ana_1,\ldots,a_n (1ai1091 \le a_i \le 10^9 for each ii), where aia_i is the amount of energy released when an atom with ii neutrons is explodificated.
  • Then qq lines follow, each with an integer kk (1k1091 \le k \le 10^9), asking for the minimum energy released when an atom with kk neutrons is explodificated.

Output Format

For each query kk, output the minimum energy released when an atom with kk neutrons is explodificated.

4 5
2 3 5 7
2
3
5
6
8
3
5
8
10
13
1 3
10
1
2
100
10
20
1000