Comments

I think its possible you are generating more than 2000010 different values, since your inner loop runs around ~59 times

if( a[i]*k > maxx/2 )

and there could be up to 150 000 different values you will end with more than 2M elements.

I think kapillamba4 is right idx could have a huge value since its based on elements in vector b:

idx[cnt] = b[i];

Try with:

6
1 3 2 2 2 2

Answer should be:

2
1 1 1 3 3 3

I hope to it will be distributed in both divisions.