text: Minimize sum of smallest elements from K subsequences of length L | C ++ Program to find the minimum possible sum of the smallest elements from K subsequences ; Function to find the minimum sum ; Sort the array ; Calculate sum of smallest K elements ; Return the sum ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinSum ( int arr [ ] , int K , int L , int size ) { if ( K * L > size ) return -1 ; int minsum = 0 ; sort ( arr , arr + size ) ; for ( int i = 0 ; i < K ; i ++ ) minsum += arr [ i ] ; return minsum ; } int main ( ) { int arr [ ] = { 2 , 15 , 5 , 1 , 35 , 16 , 67 , 10 } ; int K = 3 ; int L = 2 ; int length = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMinSum ( arr , K , L , length ) ; return 0 ; }