Input: N = 7, A[] = {3, 3, 4, 5, 2, 6, 1}
Output: 0
Explanation: Initially, A[] = {3, 3, 4, 5, 2, 6, 1}
- Performing first operation: Remove A1 = 3 and also remove next 3 elements with cost 0. Updated A[] becomes: {2, 6, 1}
- Performing first operation: Remove A1 = 2 and also remove next 2 elements with cost 0. Updated A[] becomes: {}
It can be seen that A[] has no elements left. Then total cost is 0.
Input: N= 5, A[] = {1, 2, 3, 4, 5}
Output: 2
Explanation: Initially, A[] = {1, 2, 3, 4, 5}
- Performing second operation: Remove A1 = 1 with cost 1. Updated A[] is: {2, 3, 4, 5}
- Performing first operation: Remove A1 = 2 and also remove next 2 elements with cost 0. Updated A[] becomes: {5}
- Performing second operation: Remove A1 = 5 with cost 1. Updated A[] becomes: {}
Total cost to remove all the elements is 2.