Programming Practice challenge : Fredo and Array Update
Programming Practice challenge Fredo and Array Update Hacker Earth Problem.
Problem:
Fredo and Array UpdateMax. score: 100Fredo is assigned a new task today. He is given an array A containing N integers. His task is to update all elements of array to some minimum value x , that is, ; such that sum of this new array is strictly greater than the sum of the initial array. Note that x should be as minimum as possible such that sum of the new array is greater than the sum of the initial array.
Input Format:
First line of input consists of an integer N denoting the number of elements in the array A.
Second line consists of N space separated integers denoting the array elements.
Output Format:
The only line of output consists of the value of x.
Input Constraints:
ExplanationInitial sum of array
When we update all elements to 4, sum of array which is greater than .
Note that if we had updated the array elements to 3, which is not greater than . So, 4 is the minimum value to which array
Fredo is assigned a new task today. He is given an array A containing N integers. His task is to update all elements of array to some minimum value x , that is, ; such that sum of this new array is strictly greater than the sum of the initial array. Note that x should be as minimum as possible such that sum of the new array is greater than the sum of the initial array.
Input Format:
First line of input consists of an integer N denoting the number of elements in the array A.
Second line consists of N space separated integers denoting the array elements.
Output Format:
The only line of output consists of the value of x.
Input Constraints:
Initial sum of array
When we update all elements to 4, sum of array which is greater than .
Note that if we had updated the array elements to 3, which is not greater than . So, 4 is the minimum value to which array
Comments
Post a Comment