This comes as an application to this question:Sum object in a column between an interval defined by another column
What I would like to know is how to adjust the answer
I would create a for loop that tests whether A[i] - A[i-1] meets your criteria.
If that is true it adds b[i] to a sum variable and repeats its way through.
Because i is just iterating through A[] it shouldn't count anything from B[] twice.