Solution , see for reference :)


#1
#define pb push_back
#define ll long long
#define fl(i,x,y) for(ll i=x;i<=y;i++)
#define a A
#define b B
#define c C
#define nl '\n'
#define ub upper_bound
#define lb lower_bound
#define node TreeNode
#define null nullptr
#define P pair
#define mkp(x,y) make_pair(x,y)
#define x first
#define y second
int dp[100][1000][40];
int check(vector<int>&a,int i,int j,int sum,int size,vector<int> &v){
    //cout<<i<<" "<<j<<" "<<sum<<" "<<size<<nl;
    if(size==0 && sum==0) return 1;
    if(size==0) return 0;
    if(i > j) return 0;
    if(dp[i][sum][size]!=-1) return dp[i][sum][size];
    if(a[i] <= sum){
        v.pb(i);
        if(check(a,i+1,j,sum-a[i],size-1,v)) return 1;
        v.pop_back();
        dp[i][sum][size]=0;
    }
    if(check(a,i+1,j,sum,size,v)) return 1;
    return dp[i][sum][size]=0;
}
vector<vector<int> > Solution::avgset(vector<int> &A) {
    fl(i,0,99) fl(j,0,999) fl(k,0,39) dp[i][j][k]=-1;
    int n=a.size();
    sort(a.begin(),a.end());
    int s=0;
    vector<vector<int>> ans;
    if(n <=1) return ans;
    fl(i,0,n-1) s+=a[i];
    fl(i,1,n-1){
        if(s*i%n==0){
            vector<int> v;
            //cout<<((s*i)/n)<<" ";
            if(check(a,0,n-1,((s*i)/n),i,v)==1){
                set<int> ind;
                //cout<<v.size()<<" ";
                for(auto x:v) ind.insert(x);
                vector<int> o,p;
                fl(i,0,n-1){
                    if(ind.find(i)!=ind.end()){
                        o.pb(a[i]);
                    }else p.pb(a[i]);
                }
                
                ans.pb(o); ans.pb(p);
                return ans;
            }
        }
    }
    return ans;
}