implicit none integer(8) i,l,n,m,e,f integer(8),allocatable :: c(:) integer(8),allocatable :: d(:) read(*,*) n,m allocate (c(n)) allocate (d(1:n)) c=0 d=0 e=0 f=0 read(*,*) (C(l),l=1,n) do i=1,n d(i)=maxval(c) c(maxloc(c))=0 end do do while (m>e) e=e+d(n) n=n-1 f=f+1 end do if (e==m) then write(*,*) f else write(*,*) f-1 end if end