Equally divide into two sets such that one set has maximum distinct elements | C ++ program to equally divide n elements into two sets such that second set has maximum distinct elements . ; Driver code
#include <algorithm> NEW_LINE #include <iostream> NEW_LINE using namespace std ; int distribution ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) count ++ ; return min ( count , n / 2 ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 1 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << distribution ( arr , n ) << endl ; return 0 ; }