The approach you have chosen is not optimal as you are assigning the order starting from index 0.
The greedy parameter should be on the absolute value of the difference between the tips of Andy and Bob. When you assign a delivery to eitehr Andy( tip = x) or Bob(tip = y), the final answer changes by the difference of the two tips i.e. (x-y).
We basically sort the tips in descending order of absolute value of difference between the tips. Now, choosing the index where the difference between the tips is higher allows us to prioritise that delivery first.
Consider the following test case.
N = 3, X = 2, Y = 1;
a = [1, 2, 3]
b = [2, 1, 10]
Your approach would have given the first order to Y ...