Maximum possible value of array elements that can be made based on given capacity conditions | C # program for the above approach ; Function to find the maximum element after shifting operations in arr [ ] ; Stores the sum of array element ; Stores the maximum element in cap [ ] ; Iterate to find maximum element ; Return the resultant maximum value ; Driver Code
using System ; class GFG { public static int maxShiftArrayValue ( int [ ] arr , int [ ] cap , int N ) { int sumVals = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sumVals += arr [ i ] ; } int maxCapacity = 0 ; for ( int i = 0 ; i < N ; i ++ ) { maxCapacity = Math . Max ( cap [ i ] , maxCapacity ) ; } return Math . Min ( maxCapacity , sumVals ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 } ; int [ ] cap = { 5 , 6 } ; int N = arr . Length ; Console . WriteLine ( maxShiftArrayValue ( arr , cap , N ) ) ; } }