Pagini recente » Cod sursa (job #2408493) | Cod sursa (job #62120) | Cod sursa (job #1989981) | Cod sursa (job #1529269) | Cod sursa (job #253699)
Cod sursa(job #253699)
var n,m,i,j,q,sum,max,x,max1,r,s:longint;
c:array[1..1000000]of longint;
f,g:text;
begin
assign(f,'caramizi.in');reset(f);
assign(g,'caramizi.out');rewrite(g);
readln(f,n,m);s:=0;
for i:=1 to n do begin
read(f,c[i]);
s:=s+c[i];
end;
for i:=1 to m do begin
read(f,x);
max:=s;
if max>x then max:=x;
q:=0;max1:=0;
while (max>0)and(q=0) do begin
sum:=0;
for j:=1 to n do if c[j]>=max then sum:=sum+max
else sum:=sum+c[j];
r:=sum - (sum mod max);
if r>max1 then max1:=r;
dec(max);
if max1>=n*max then q:=1;
if max1>=sum then q:=1;
end;
writeln(g,max1);
end;
close(f);
close(g);
end.