Pagini recente » Cod sursa (job #2219921) | Cod sursa (job #1510809) | Cod sursa (job #1249960) | Cod sursa (job #2307879) | Cod sursa (job #1201817)
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const int DIM = 8192, Nmax = 200009, oo = 1000009;
LL n, m, c, pz, V[Nmax];
char ax[DIM];
LL sol = -1, dp[oo];
inline void cit(LL &x)
{
x = 0;
while (ax[pz] < '0' || ax[pz] > '9')
if (++pz == DIM) fread(ax, 1, DIM, stdin), pz = 0;
while (ax[pz] >= '0' && ax[pz] <= '9')
{
x = x * 10 + (ax[pz] - '0');
if (++pz == DIM) fread(ax, 1 ,DIM, stdin), pz = 0;
}
}
int main()
{
freopen ("caramizi.in", "r", stdin);
freopen ("caramizi.out", "w", stdout);
cit(n); cit(m);
for (int i=1; i<=n; i++)
cit(V[i]);
V[0] = 1;
V[n+1] = oo;
sort (V+1, V+1+n);
for (int i=0; i<=n; i++)
{
sol += V[i];
for (int j=V[i]; j<V[i+1]; j++)
{
dp[j] = max (dp[j-1], sol/j*j + (n-i)*j);
}
}
for (int i=1; i<=m; i++)
{
cit(c);
if (c < oo) printf("%lld\n", dp[c]);
else printf("%lld\n", sol);
}
return 0;
}