0
点赞
收藏
分享

微信扫一扫

Tyvj Q1033(线性扫描)


Q1033 - Unit9 - 智力值 From ​​Admin​​    Normal (OI)

总时限:5s    内存限制:128MB    代码长度限制:64KB

描述 Description


WJ是个很聪明的人,他有一个智力值。 
和比他聪明的人(智力值大于WJ)辩论一次智力值会+2。
和比他笨的人(智力值小于等于WJ)辩论一次智力会+1。
然后每个人只能辩论一次。安排一个辩论顺序。使得辩论完后WJ的智商最高。

输入格式 InputFormat


第一行包含两个正整数n和k,表示要和WJ辩论的人数,以及WJ的初始智力值。
第二行包含n个正整数,表示这n个人的智力值。

输出格式 OutputFormat


第一行包含一个正整数,表示WJ最终智力值的最大值。

样例输入 SampleInput [​​复制数据​​]



5 9188 90 92 94 98


样例输出 SampleOutput [​​复制数据​​]



99


数据范围和注释 Hint


数据范围:
   1<=n<=500 智力值范围<=1000





每次贪心贪比他聪明的人中最不聪明的



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.




举报

相关推荐

0 条评论