text: Maximize the first element of the array such that average remains constant | C # implementation of to maximize the first element of the array such that average of the array remains constant ; Maximum value of the first array element that can be attained ; Variable to store the sum ; Loop to find the sum of array ; Desired maximum value ; Driver code
code: using System ; class GFG { static void getmax ( int [ ] arr , int n , int x ) { int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s = s + arr [ i ] ; } Console . WriteLine ( Math . Min ( s , x ) ) ; } static void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 } ; int x = 5 ; int arr_size = arr . Length ; getmax ( arr , arr_size , x ) ; } }