<div dir="ltr">Hi all,<div>I learn Haskell and i try to solve questions from SPOJ.<div><br></div><div>Currently, i try to solve problem <a href="http://www.spoj.com/problems/SBANK/" style="font-size:13px;text-decoration:none;color:rgb(0,0,160);font-family:Verdana,Arial,Helvetica,sans-serif;background-color:rgb(208,208,208)"><b>Sorting Bank Accounts</b></a></div>
<div><br></div><div>Here is my code:</div><div><br></div><div><div><b>import qualified Data.Map as M</b></div><div><b><br></b></div><div><b>extractTest []=[]</b></div><div><b>extractTest (x:xs)=(take n xs):(extractTest (drop (n+1) xs)) where</b></div>
<div><b><span class="" style="white-space:pre">        </span>n=read x</b></div><div><b><br></b></div><div><b>emp=M.empty</b></div><div><b><br></b></div><div><b>collect m []=m</b></div><div><b>collect m (x:xs)</b></div><div><b><span class="" style="white-space:pre">        </span>|M.member x m =collect (M.insert x (amount+1) m) xs</b></div>
<div><b><span class="" style="white-space:pre">        </span>|otherwise=collect (M.insert x 1 m) xs</b></div><div><b><span class="" style="white-space:pre">        </span>where</b></div><div><b><span class="" style="white-space:pre">                </span>Just amount=M.lookup x m</b></div>
<div><b><br></b></div><div><b>getList m=map (\(x,k)-&gt;x++&quot; &quot;++(show k)) (M.toList m)</b></div><div><b>f x=unlines$(getList (collect emp x))++[&quot;&quot;]</b></div><div><b>main=getLine&gt;&gt;=(\x-&gt;interact$unlines.map f.take (read x).extractTest.lines)</b></div>
</div><div><b><br></b></div><div>The problem is that i can&#39;t finish it during 7 sec.</div><div>So i want to know is there more quick solution/method for this problem.</div><div>Thanks, Nadav</div></div></div>