You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
The first element to be picked should be A[1]
The last element to be picked should be A[n]
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
Uh oh!
There was an error while loading. Please reload this page.
Given an array of integers
A
of sizeN
and an integerB
.You have to pick some elements from the array
A
while picking you have to follow the given conditions:A[1]
A[n]
A[j]
afterA[i]
, then it should follow the constraintsj-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
The text was updated successfully, but these errors were encountered: