Q1033 - Unit9 - 智力值From Admin Normal (OI)总时限:5s 内存限制:128MB 代码长度限制:64KB | ||||||
---|---|---|---|---|---|---|
|
每次贪心贪比他聪明的人中最不聪明的
const
maxn=5000;
var
n,i,j,now,tot:longint;
a:array[1..maxn] of longint;
procedure qsort(l,r:longint);
var
i,j,m,p:longint;
begin
i:=l;
j:=r;
m:=a[(l+r) div 2];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then
begin
p:=a[i];
a[i]:=a[j];
a[j]:=p;
inc(i);
dec(j);
end;
until i>j;
if (l<j) then qsort(l,j);
if (i<r) then qsort(i,r);
end;
begin
read(n,now);
tot:=0;
for i:=1 to n do read(a[i]);
qsort(1,n);
for i:=1 to n do
begin
if (now<a[i]) then inc(now,2)
else inc(tot);
end;
writeln(tot+now);
end.