Skip to content

Maximum sum of all picked elements #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hamidgasmi opened this issue Aug 23, 2020 · 0 comments
Open

Maximum sum of all picked elements #277

hamidgasmi opened this issue Aug 23, 2020 · 0 comments
Assignees

Comments

@hamidgasmi
Copy link
Owner

hamidgasmi commented Aug 23, 2020

Given an array of integers A of size N and an integer B.
You have to pick some elements from the array A while picking you have to follow the given conditions:

  1. The first element to be picked should be A[1]
  2. The last element to be picked should be A[n]
  3. If you pick some element A[j] after A[i], then it should follow the constraints j-i >= B, j-i <= 2*B

Return the maximum sum of all picked elements.

Note: Array A has 1-based indexing.

Constraints:
1 ≤ N ≤ 10^5
1 ≤ A[I] ≤ 10^5
1 ≤ B ≤ N

Example:
A = [7, 9, 3, 8, 11, 10] , B = 2
Output: 25
Explanation: You pick {7, 8, 10}

Example:
A = [5, 4, 3, 2, 1], B = 1
Output: 15
Explanation: You pick all elements

For more details

@hamidgasmi hamidgasmi self-assigned this Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant