[2nd version]Contest problem: 1423. Maximum Points You Can Obtain from Cards
Solution 2
The problem I failed stated as followed:
Given a list of numbers (with M cards)and the amount of picking (K), we should return the maximum possible summary of the picked series. Each time we should only pick the rightmost or the leftmost.
Maximum summary method:
This solution is equivalent to finding k (integer) continuous numbers from the leftmost and K-k continuous numbers from the rightmost that has the maximum summary.
So the algorithm is as following:
1. Use the Maximum summary method. The difference of summary between the sequential two series is the first card and the last card. So, add the number of the last card and minus the number of the first card in the previous series.
2. Store the summary of first picking list: pick the 1st to the Kth number
3. Try every other possible case in either of the methods, replace the stored summary with the new one when the calculated summary larger than the stored summery.