Question: use c ++ Description Find the maximum value of an array with length N after X operations. The initial value of all elements of the
use c ++ Description Find the maximum value of an array with length N after X operations. The initial value of all elements of the array is 0
Constraint 10 <= N <= 10 ^ 6
10 <= X <= 10 ^ 6
10 <= array [N] <= 10 ^ 6
Example Input:
11 4 1 4 5 3 10 2 7 9 10 2 5 6 Output:
13 How to count
Line length (n) = 11 Many operations (x) = 4
| Operation to | start (s) | end (e) | value (v) | | 1 | 1 | 4 | 5 | ... (1) | 2 | 3 | 10 | 2 | ... (2) | 3 | 7 | 9 | 10 | ... (3) | 4 | 2 | 5 | 6 | ... (4)
Index -> 1- 2- 3- 4- 5- 6- 7- 8- 9- 10 11 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] <- Initial value of the row [5, 5, 5, 5, 0, 0, 0, 0, 0, 0] <- Value after 1st operation [5, 5, 7, 7, 2, 2, 2, 2, 2, 2, 0] <- Value after the 2nd operation [5, 5, 7, 7, 2, 2, 12, 12, 12, 2, 0] <- Value after the 3rd operation [5, 11, 13, 13, 8, 2, 12, 12, 12, 2, 0] <- Value after the 4th operation
Max-> 13
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
