Help with ZCO SUPW

I saw the hints on common lounge and came up with a dp solution but it gives tle for most of the case, could you help me?
Here is my solution:
Btw I am just learning dp so I am sorry if my practices are wrong, it would be awesome if you could help me with that also.

I haven’t read the question or your solution very well but try changing vector<int> a in line 5 to vector<int>& a.

That way it will be passed by reference and not copied every time you call the function.

1 Like

WOW, I just got AC by doing that.

1 Like