Hello all , i am trying to solve this problem [ hpaste.org/483081 ].

import Data.List
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Array 
bHelper ::Int -> Int -> Integer -> Integer -> Array Int Integer  -> Bool
bHelper cnt b k amt arr
	| cnt > b = if k<=0 then True else False  
	| otherwise = if k <= 0 then True else bHelper ( cnt+1 ) b ( k - div ( arr!cnt ) amt ) amt arr   
{--bHelper k amt [] = if k<=0 then True else False  
bHelper k amt (x:xs) 
   | k<=0 = True
   | otherwise = bHelper ( k - div x amt ) amt xs	
--}
bSearch ::Array Int Integer -> Integer -> Integer
bSearch arr k = bsearchHelp   1 ( arr!b  + 1 )  where 
        (a,b) = bounds arr
	bsearchHelp low high 
		| low >= high = low -1 
		| bHelper a b k mid arr == True = bsearchHelp ( mid + 1 ) high 
		| otherwise = bsearchHelp  low mid 
		where 
			mid = div ( low + high ) 2 	
solve::[Integer] -> BS.ByteString
solve (n:k:xs) = BS.pack.show.bSearch ( listArray (  0 ,length xs - 1 ) $   sort xs   )  $ k 
readInt :: BS.ByteString -> Integer
readInt x = case BS.readInteger x of
              Just ( i , _ ) -> i
	      Nothing -> error " upseperable ints "
format :: [BS.ByteString] -> [BS.ByteString]
format [] = []
format (x:y:xs ) = BS.append ( BS.append x (BS.pack " ") ) y :format xs
main = BS.interact $ BS.unlines . map  ( solve .map readInt . BS.words) . format . tail . BS.lines