It's not giving the valid result

Would you please check for this data set, answer should
be 4
5 3
1 2 4 8 9 12

In line 4 initialize last_cow with -INF, so that you can always include the first cow.