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 sum of all the updated array elements is strictly greater than the sum of all the elements of the initial array and **X** is 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 = 25

Input:arr[] = {9876, 8654, 5470, 3567, 7954}

Output:7105

**Approach:**

- Find the sum of the original array elements and store it in a variable
**sumArr** - Calculate
**X = sumArr / n**where**n**is the number of elements in the array. - Now, in order to exceed the sum of the original array, every element of the new array has to be at least
**X + 1**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the minimum ` `// required value ` `int` `findMinValue(` `int` `arr[], ` `int` `n) ` `{ ` ` ` ` ` `// Find the sum of the ` ` ` `// array elements ` ` ` `long` `sum = 0; ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `sum += arr[i]; ` ` ` ` ` `// Return the required value ` ` ` `return` `((sum / n) + 1); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `arr[] = { 4, 2, 1, 10, 6 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(` `int` `); ` ` ` ` ` `cout << findMinValue(arr, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to return the minimum ` ` ` `// required value ` ` ` `static` `int` `findMinValue(` `int` `arr[], ` `int` `n) ` ` ` `{ ` ` ` ` ` `// Find the sum of the ` ` ` `// array elements ` ` ` `long` `sum = ` `0` `; ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) ` ` ` `sum += arr[i]; ` ` ` ` ` `// Return the required value ` ` ` `return` `((` `int` `)(sum / n) + ` `1` `); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `arr[] = { ` `4` `, ` `2` `, ` `1` `, ` `10` `, ` `6` `}; ` ` ` `int` `n = arr.length; ` ` ` ` ` `System.out.print(findMinValue(arr, n)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the minimum ` `# required value ` `def` `findMinValue(arr, n): ` ` ` ` ` `# Find the sum of the ` ` ` `# array elements ` ` ` `sum` `=` `0` ` ` `for` `i ` `in` `range` `(n): ` ` ` `sum` `+` `=` `arr[i] ` ` ` ` ` `# Return the required value ` ` ` `return` `(` `sum` `/` `/` `n) ` `+` `1` ` ` `# Driver code ` `arr ` `=` `[` `4` `, ` `2` `, ` `1` `, ` `10` `, ` `6` `] ` `n ` `=` `len` `(arr) ` `print` `(findMinValue(arr, n)) ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the above approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the minimum ` ` ` `// required value ` ` ` `static` `int` `findMinValue(` `int` `[]arr, ` `int` `n) ` ` ` `{ ` ` ` ` ` `// Find the sum of the ` ` ` `// array elements ` ` ` `long` `sum = 0; ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `sum += arr[i]; ` ` ` ` ` `// Return the required value ` ` ` `return` `((` `int` `)(sum / n) + 1); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main () ` ` ` `{ ` ` ` `int` `[]arr = { 4, 2, 1, 10, 6 }; ` ` ` `int` `n = arr.Length; ` ` ` ` ` `Console.WriteLine(findMinValue(arr, n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

**Output:**

5

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Length of longest subarray in which elements greater than K are more than elements not greater than K
- Find minimum value to assign all array elements so that array product becomes greater
- Maximum score assigned to a subsequence of numerically consecutive and distinct array elements
- Adding elements of an array until every element becomes greater than or equal to k
- Smallest subarray of size greater than K with sum greater than a given value
- Remove minimum elements from either side such that 2*min becomes more than max
- Remove minimum elements from either side such that 2*min becomes more than max | Set 2
- Remove minimum elements from the array such that 2*min becomes more than max
- Find the minimum value to be added so that array becomes balanced
- Count of alphabets having ASCII value less than and greater than k
- Sum of all array elements less than X and greater than Y for Q queries
- Merge first two minimum elements of the array until all the elements are greater than K
- Minimum value of K such that sum of cubes of first K natural number is greater than equal to N
- Minimum Initial Energy Required To Cross Street
- Count of Array elements greater than all elements on its left and at least K elements on its right
- Count of Array elements greater than all elements on its left and next K elements on its right
- Count of elements that can be deleted without disturbing the mean of the initial array
- Largest number less than N with digit sum greater than the digit sum of N
- Add minimum number to an array so that the sum becomes even
- Insert minimum number in array so that sum of array becomes prime

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.