Pagini recente » Cod sursa (job #448815) | Cod sursa (job #1209864) | Cod sursa (job #2614509) | Cod sursa (job #714194) | Cod sursa (job #506)
Cod sursa(job #506)
program grupuri;
const
fin='grupuri.in';
fout='grupuri.out';
nmax=100000;
var
a:array[1..nmax] of longint;
i,j,l:longint;
n,s,nr,k:int64;
st,dr,mid,max:int64;
begin
assign(input,fin);
reset(input);
readln(k,n);
s:=0;
for i:=1 to n do
begin
read(a[i]);
inc(s,a[i]);
end;
close(input);
assign(output,fout);
rewrite(output);
st:=1;dr:=s div k;
max:=0;
while (st<=dr) do
begin
mid:=(st+dr) shr 1;
nr:=0;
for i:=1 to n do
if a[i]<=mid then
inc(nr,a[i])
else
inc(nr,mid);
if nr>=mid*k then
begin
st:=mid+1;
if mid>max then
max:=mid;
end
else
dr:=mid-1;
end;
writeln(max);
close(output);
end.