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
#include <bits/stdc++.h> NEW_LINE using namespace std ; 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 = max ( cap [ i ] , maxCapacity ) ; } return min ( maxCapacity , sumVals ) ; } int main ( ) { int arr [ ] = { 2 , 3 } ; int cap [ ] = { 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxShiftArrayValue ( arr , cap , N ) ; return 0 ; }