You are given N numbers placed in a line. You have to select K numbers from those numbers. The priority level of the numbers is different.
You can select numbers from end only. After selection the number gets erased from the line. You want to maximize the sum of priority level of all the numbers. Your task is to find the maximum sum of the priority values.
Input format
First line contains K and N.
Second line contains N space separated integers denoting the priority of numbers in the list.
Output format
Maximum sum of priority of K numbers
Constraints
\(1\le K \le N \le 10^{5} \)
\( 0 \le A_{i} \le 10^{9} \)
Sum of priorities will be maximised if he selects \(4^{th}\) chocolate first , followed by \(3^{rd}\) one
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor