这道题不是很难,二分答案+判定即可
注意在一套牌中Joker只能用一次
1 var a:array[0..51] of longint; 2 mid,l,r,n,m,i,ans:longint; 3 4 function check(x:longint):boolean; 5 var i,t:longint; 6 begin 7 t:=m; 8 if t>x then t:=x; //判定的关键 9 for i:=1 to n do 10 if a[i]<x then 11 begin 12 t:=t-x+a[i]; 13 if t<0 then exit(false); 14 end; 15 exit(true); 16 end; 17 18 begin 19 readln(n,m); 20 for i:=1 to n do 21 read(a[i]); 22 l:=1; 23 r:=1000000000; 24 while l<=r do 25 begin 26 mid:=(l+r) shr 1; 27 if check(mid) then 28 begin 29 ans:=mid; 30 l:=mid+1; 31 end 32 else r:=mid-1; 33 end; 34 writeln(ans); 35 end.