Your program fails on the following test case
`1
10
1
3
5
7
9
2
4
6
8
10
(outputs 25 instead of 10)
It fails because in the
join_vectorsfunction you are accessing elements out of bounds in arrays
i_leftand
i_right. This leads to undefined behaviour in C++ (read more https://stackoverflow.com/questions/1239938/accessing-an-array-out-of-bounds-gives-no-error-why). A simple fix for this testcase is to change line 12 to
if ( (j == i_right.size() ) || (i != i_left.size() && i_left[i] < i_right[j])) {v[k] = i_left[i]; ++i;}`
in order to avoid these invalid accesses.