Please help me debug whats wrong in my code.
#include<iostream>
#include<queue>
#define ll long long
using namespace std;
class node{
public:
ll data;
ll x; // arr index
ll y; // ele index
// constructor
node(ll d, ll x, ll y){
data = d;
this->x = x;
this->y = y;
}
};
vector<ll> mergeKSortedArrays(vector<vector<ll>> a){
vector<ll> result;
priority_queue<node,vector<node>,greater<node>> pq;
// insert 0th element of all K-arrays llo min-heap/priority queue
for(ll i=0; i<a.size(); i++){
pq.push(node(a[i][0], i, 0));
}
while(!pq.empty()){
node current = pq.top();
pq.pop();
ll ele_value = current.data;
ll X = current.x; // arr index
ll Y = current.y; // ele index
result.push_back(ele_value);
// push next element(to cuurent element) in pq, which will be at position (X,Y+1)
if(Y+1 < a[X].size()){
pq.push(node(a[X][Y+1], X, Y+1));
}
}
return result;
}
int main() {
ll K,N;
cin>>K>>N;
vector<vector<ll>> v;
for(ll i=0; i<K; i++){
for(ll j=0; j<N; j++){
cin>>v[i][j];
}
}
vector<ll> ans = mergeKSortedArrays(v);
for(auto x:ans){
cout<<x<<" ";
}
return 0;
}