Allocating tasks among two people equitably Given that we have 2 people, and 2n tasks, find the minimum time to complete the tasks. Both persons should solve exactly n tasks each and any task j has to be solved before task j+1. Required time complexity is O(nlogn).
E.g- given this input: 

A B

5 3

2 1

3 2

1 2

the intended output is 8, because A solves the second and fourth task, and B solves the first and second.
Suppose that the time for completing task $i$ is $a_i$ for $A$ and $b_i$ for $B$. Let $S$ be the set of tasks performed by $B$. The total time required is
$$
\sum_i a_i + \sum_{i \in S} (b_i-a_i).
$$
Your goal is then to find a subset $S \subseteq [2n]$ of size $n$ which maximizes $\sum_{i \in S} (b_i - a_i)$. You take it from here.