read n k a=(`tr ' ' '\n' | sort -nr`) if((a[0]<0)) then echo ${a[0]} else a=(`sed -r "s/\-[0-9]+//g" | tr ' ' '\n' | sort -nr | head -$k`) echo $((`echo ${a[@]} | tr ' ' '+'`)) fi