Help me Debug ENTRANCE

Here is the link the link to the problem

here is the link to my solution

codechef.com/viewsolution/39076663

kindly help me out

try this testcase:

4 2 3 10
2 7 7
4 1 10
0 10 1
10 10

o/p should be 0

Size of m is large sum and last_sum won’t fit in integer size. Use long or long long.

Tried both but didn’t work help me debug this there is some corner case which I am missing I think