Farmer John finds that his cows are each easier to milk when they have another cow nearby for moral support. He therefore wants to take his M cows (M≤1000000000, M even) and partition them into M/2 pairs. Each pair of cows is then ushered off to a separate stall in the barn for milking. The milking in all M/2 stalls takes place simultaneously.
Each cow has its own milk output. If cows with milk outputs A and B are paired up, it takes a total of A+B units of time to milk them both.
Determine the minimum possible amount of time the entire milking process takes to complete, assuming Farmer John pairs the cows up in the best possible way.