#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout << x << " " << y << endl
#define N 200005
using namespace std;
int t[N];
int n, m;
vector<int> type_machine[1005];
vector<pair<int, long long> > sum[1001][1001];
long long limit = 1000000000LL;
bool can(long long temp, int need){
vector<pair<int, long long> >::iterator it;
long long total = 0, lenMachine;
int l = int(min(limit, temp));
for(int i = 1; i <= 1000; i++){
if(type_machine[i].size() == 0)continue;
// we use upper bound to chose the correct sum range given some time "temp"
it = upper_bound(all(sum[i][temp%i]), make_pair(l, limit));
if(it == sum[i][temp%i].begin())continue;
it--;
lenMachine = it - sum[i][temp%i].begin() + 1;
total += (temp/i) * lenMachine + (it->second);
}
return total >= need;
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++)
scanf("%d", &t[i]);
sort(t, t + n);
//after the greedy step of sorting to get as many working machines as we can
//we need to evaluate for certain x copies:
// x/t[0] + (x - t[0])/t[1] + (x - 2*t[0])/t[2] + .....
for(long long i = 0; i < n; i++)
type_machine[t[i]].pb(i * t[0]);
long long aux, add, cur;
for(int i = 1; i <= 1000; i++){
if(type_machine[i].size() == 0)continue;
for(int j = 0; j < i; j++){ //possible reminder for some number of copies when you are using machine i
cur = 0;
for(int k = 0; k < type_machine[i].size(); k++){
aux = j - type_machine[i][k];
if(aux >= 0)add = aux/i;
else{
if(aux%i == 0)add = aux/i;
else add = aux/i - 1;
}
cur += add;
sum[i][j].pb(make_pair(type_machine[i][k], cur));
}
}
}
int need;
for(int i = 0; i < m; i++){
scanf("%d", &need);
long long lo = 0, hi = 1000000000000LL, me;
while(lo < hi){
me = lo + (hi - lo)/2;
if(can(me, need))hi = me;
else lo = me + 1;
}
printf("%I64d\n", lo);
}
}
CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIHBiKHgpIHB1c2hfYmFjayh4KQojZGVmaW5lIGNvdXQ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