You have to pull out all of n stones.
You can only pull out one at a time.
The cost to pull out the ith stone is as follows(0<=i<N):
Example:
n=5
A[i]=[1,5,3,4,3]
B[i]=[0,2,1,5,0]
Answer:5
If stones are pulled out in the order of 0->2->4->1->3
1+1+3+0+0=5
n=4
a[]=[3,3,2,0]
B[]=[0,2,3,0]
Answer:2
If the stones are pulled out in the order of 1->3->0->2
2+0+0+0=2
Constraints
1<= N <= 50000
Any ideas on how this can be solved?