read l n s=0 i=0 for j in $(tr ' ' '\n' | sort -n); do s=$((s+j)) echo $l $s if [ $l -ge $s ] ; then i=$((i+1)) fi done echo $i