Your y
vector is never allocated any space before you use operator[]
to dereference its elements. Specifically this:
y[k] = N[i] - a[j];
Pretty sure you want to push_back()
that, or preallocate the space. Either way, dereferencing even the zero-index of a zero-sized vector isn't good.