Time Limit Exceeded (but correct solution)


#1

vector Solution::solve(vector< int> &A, vector< int> &B, int C) {
priority_queue<int,vector< int>,greater< int>> pq;
int val=0;
sort(A.begin(),A.end(),greater< int>());
sort(B.begin(),B.end(),greater< int>());
for(int i=0;i<C;i++){
for(int j=0;j<C;j++){
val=A[i]+B[j];
pq.push(val);
if(pq.size()>C) pq.pop();
}
}
vector v©;
while(pq.size()>0){
v[C-1]=pq.top();
C - -;
pq.pop();
}
//sort(v.begin(),v.end(),greater< int>());
return v;
}