Maximum sum obtained by dividing Array into several subarrays as per given conditions | C # program for the above approach ; Function to find the required answer ; Stores maximum sum ; Adding the difference of elements at ends of increasing subarray to the answer ; Driver Code ; Input ; Functio calling
using System ; using System . Collections . Generic ; class GFG { static int maximumSum ( int [ ] arr , int N ) { int Sum = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) Sum += ( arr [ i ] - arr [ i - 1 ] ) ; } return Sum ; } public static void Main ( ) { int [ ] arr = { 1 , 5 , 3 } ; int N = arr . Length ; Console . Write ( maximumSum ( arr , N ) ) ; } }