Selection of Numbers
Practice
3.1 (14 votes)
Algorithms
Dynamic programming
Medium
Prefix sum
Prefix sum
Problem
77% Success 1506 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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} \)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
15 votes
Tags:
AlgorithmsDynamic ProgrammingHiringMedium
Points:30
5 votes
Tags:
AlgorithmsDynamic ProgrammingMedium
Points:30
7 votes
Tags:
Ad-HocApprovedBasic ProgrammingBrute ForceDynamic ProgrammingMediumOpenSieve