I think you can think along this direction:-
Obtain the max element of A and min element of B.
Binary Search [The inputs are sorted in the example] or Simple search to get two bounds.
2.1 Find all the elements in B that are smaller than the largest element in A.
2.2 Find all the elements in A that are larger than smallest element of B.
After getting the bounds from above just calculate the cost for both the cases take the minimum one. The cost would basically be the total number of operations required for a bound to reach a particular element i.e. either max element of A or min element of B.
Time_Complexity:- O(N)