![]() |
VOOZH | about |
Given an array arr[] of N elements, the task is to update all the elements of the given array to some value X such that the sum of all the updated array elements is strictly greater than the sum of all the elements of the initial array and X is the minimum possible.
Examples:
Input: arr[] = {4, 2, 1, 10, 6}
Output: 5
Sum of original array = 4 + 2 + 1 + 10 + 6 = 23
Sum of the modified array = 5 + 5 + 5 + 5 + 5 = 25Input: arr[] = {9876, 8654, 5470, 3567, 7954}
Output: 7105
Approach:
Below is the implementation of the above approach:
5
Time Complexity: O(N).
Auxiliary Space: O(1).