C ++ program to equally divide n elements into two sets such that second set has maximum distinct elements .
#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 ) ; }