i am getting run time error sigdegv fault , please tell where my code going wrong?
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T–){
int K,q; // K- no of chefs , q - queries
cin>>K;
cin>>q;
int A[K], B[K];
for(int i=0;i<K;i++){
cin>>A[i];
}
for(int i=0;i<K;i++){
cin>>B[i];
}
sort(A, A+K);
sort(B, B+K);
priority_queue<int>pq;
for(int i=0;i<K;i++){
for(int j=0;j<K;j++){
int sum=A[i]+B[j];
if(pq.size()<10000){
pq.push(sum); //push- used in priority queue to insert a new element in priority queue
}
else if(pq.top()>sum){ // top -topmost element of a priority quewue
pq.pop(); // pop- remove top element from the queue, which has highest priority
pq.push(sum);
}
else{
break;
}
}
}
// priority stores element in Non-decreasing order like 5 4 3 2 2 1
vector<int> ans;
while(!pq.empty()){
ans.push_back(pq.top());
pq.pop(); // vector ans contain - 5 4 3 2 2 1
}
reverse(ans.begin(),ans.end()); // vec ans contain - 1 2 2 3 4 5
while(q--){
int Q;
cin>>Q;
Q--;
cout<<ans[Q]<<"\n";
}
}
return 0;
}