Add sub arrary solution in C++