Please explain the implementation

I understood the logic pretty well, but I did not understand how will the implementation work, as in what is the role of each of these variables. Please explain the “for loop” part towards the end of the code, rest I understood.

@Ishitagambhir whats the problem sir explained the last for loop in the video. diff is keeping track of the currently req transfers and max load is keeping track of the max possible transfer that can happen .
see the three cases that sir ran on the terminal in the end dry run the code for them you will understand

@vatsal38 can the line ans = max(diff, -diff) be replaced with ans = abs(diff)
also the thing I am confused with is, that in the dry run we took only the abs value of diff into consideration
for eg if the partition is like {6} {0, 0, 10} then a transfer of “2” needs to happen, we dont think -2 or +2. But in the implementation, diff += (arr[i] - load) my question is why are we not taking abs of arr[i] - load and adding it directly

@Ishitagambhir yes it can be written as abs(diff)
in diff as sir said we are calculating while running stream so for example if -2 happens first diff becomes -2 , ans 2 and max_load 2 , then we should add next transfer req into original diff only like if in next +4 transfer happen then diff becomes 2 . ( if you took abs(a[i] - load) it becomes 4 which will lead to wrong ans .