Maximize sum of second minimums of each K length partitions of the array | C # program for the above approach ; Function to find the maximum sum of second smallest of each partition of size K ; Sort the array [ ] A in ascending order ; Store the maximum sum of second smallest of each partition of size K ; Select every ( K - 1 ) th element as second smallest element ; Update sum ; Print the maximum sum ; Driver Code ; Given size of partitions ; Given array [ ] A ; Size of the given array ; Function Call
using System ; class GFG { static void findSum ( int [ ] A , int N , int K ) { Array . Sort ( A ) ; int sum = 0 ; for ( int i = N / K ; i < N ; i += K - 1 ) { sum += A [ i ] ; } Console . Write ( sum ) ; } public static void Main ( String [ ] args ) { int K = 4 ; int [ ] A = { 2 , 3 , 1 , 4 , 7 , 5 , 6 , 1 } ; int N = A . Length ; findSum ( A , N , K ) ; } }