I was playing around with the code above and noticed that it wouldn't work in a real world situation when I make;
(setq maxlen 6500.0) and (setq lst '(1120 2705 2725 2715)).... I get back ((2715) (1120 2705 2725)) = 6550? this should be (2725 2715)(2705 1120)
(setq maxlen 6500.0) and (setq lst '(2715 1050 2725 2705)).... i get back ((2715) (1050 2705 2725)) where as this should optimize to (2725 2715 1050)(2705)