Pagini recente » Cod sursa (job #2688971) | Cod sursa (job #889461) | Cod sursa (job #2649946) | Cod sursa (job #2121591) | Cod sursa (job #1201831)
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const int DIM = 8192, Nmax = 200009, oo = 1000009;
LL n, m, c, pz, sol = -1, V[Nmax], dp[oo], rez[oo];
char ax[DIM+16];
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 (LL i=0; i<=n; i++)
{
sol += V[i];
for (LL j=V[i]; j<V[i+1]; j++)
{
dp[j] = max (dp[j-1], sol/j*j + (n-i)*j);
}
}
for (LL i=sol/V[n]; i; i--)
{
rez[i] = max (rez[i+1], sol - sol % i);
}
for (int i=1; i<=m; i++)
{
cit(c);
if (c < oo) printf("%lld\n", dp[c]);
else printf("%lld\n", rez[sol/c+1]);
}
return 0;
}