Merge K Sorted Arrays

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;
}

Hi,
u can do it without creating class also just by using pair… https://ide.codingblocks.com/s/623822

yes i know, i’ve done it with this method
but for learning purpose, i tried creating class, but somehow, it is not correct.
it will be really helpful if you could help me know, what am i doing wrong in my code.

please clear my doubt

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.