Description
Farmer John Wants To Repair A Small Length Of TheChain Link Fence Around The Pasture. He Measures TheChain Link Fence And Finds That He Needs N (1≤N&le,Chain Link Fence;20, 000) Planks Of Wood, each Having Some Integer Length Li (1≤Li≤50, 000) Units. He Then Purchases A Single Long Board Just Long Enough To Saw Into pouch belt N Planks (i.e. , whose Length Is pouch belt Sum Of The Lengths Li) . FJ Is Ignoring The "kerf" , the Extra Length Lost To Sawdust When A Sawcut Is Made; You Should Ignore It, too.
FJ Sadly Realizes That He Doesn't Own A Saw With Which To Cut The Wood, so He Mosies Over To Farmer Don's Farm With This Long Board And Politely Asks If He May Borrow A Saw.
Farmer Don, a Closet Capitalist, doesn't Lend FJ A Saw But Instead Offers To Charge Farmer John For Each Of The N-1 Cuts In The Plank. The Charge To Cut A Piece Of Wood Is Exactly Equal To Its Length. Cutting A Plank Of Length 21 Costs 21 Cents.
Farmer Don Then Lets Farmer John Decide The Order And Locations To Cut The Plank. Help Farmer John Determine The Minimum Amount Of Money He Can Spend To Create The N Planks. FJ Knows That He Can Cut The Board In Various Different Orders Which Will Result In Different Charges Since The Resulting Intermediate Planks Are Of Different Lengths.
Input
Output
Sample Input
Sample Output
Recommend reading articles: