아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Atomic Energy

시간 제한2초메모리 제한1024 MB

요약
k를 크기가 n 이하인 조각으로 나누되 크기 i인 조각의 비용이 a_i일 때 최소 총비용을 구하며, k가 10^9까지이고 질의가 10^5개 주어진다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 수학, 정수론
정답자
아직 제출이 없습니다

문제

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 k≤nk \leq n neutrons, it will be converted into a_ka\_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,j≥1i,j \geq 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.

입력

The input consists of:

  • One line with two integers nn and qq (1≤n≤1001 \leq n \leq 100, 1≤q≤1051 \leq q \leq 10^5), the neutron threshold and the number of experiments.
  • One line with nn integers a_1,…,a_na\_1,\ldots,a\_n (1≤a_i≤1091 \leq a\_i \leq 10^9 for each ii), where a_ia\_i is the amount of energy released when an atom with ii neutrons is explodificated.
  • Then qq lines follow, each with an integer kk (1≤k≤1091 \leq k \leq 10^9), asking for the minimum energy released when an atom with kk neutrons is explodificated.

출력

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

예제2

  1. 예제 1

    입력
    4 5
    2 3 5 7
    2
    3
    5
    6
    8
    
    예상 출력
    3
    5
    8
    10
    13
    
  2. 예제 2

    입력
    1 3
    10
    1
    2
    100
    
    예상 출력
    10
    20
    1000