C++ BRUTE FORCE Solution on basis of the limit of C which is 1<=C<=N


#1

vector Solution::solve(vector &A, vector &B, int C)
{
sort(A.begin(),A.end(),greater());
sort(B.begin(),B.end(),greater());
vector k;
int n=B.size();
for(int i=0;i<n/2 + n%2;i++)
{
for(int j=0;j<ceil((double)n/(i+1));j++)
{
k.push_back(A[i]+ B[j]);
}
}
for(int i=n/2 + n%2;i<n;i++)
{
k.push_back(A[i]+ B[0]);
}
sort(k.begin(),k.end(),greater());
vector c;
for(int i=0;i<C;i++)
{
c.push_back(k[i]);
}
return c;

}