Neo-Robin Hood
Time limit4sMemory limit256 MB
Choose a set of politicians to rob and a disjoint set to bribe so that total stolen money covers total bribes, maximizing the number robbed.
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Binary search, Heap
- Solved
- No attempts yet
Problem
There are aspiring politicians in Neverland. They are wealthy, but not wealthy enough to gain political influence. Since Neverland is a financially transparent haven, we know the bank statements of each politician: the -th politician () has dollars, and needs more dollars to achieve his political goals.
You are the infamous modern superhero Neo-Robin Hood. You earn your living by stealing from the rich and wealthy, in order to help... well, whoever promises to help you back. For each of the politicians you can choose to do one of the following:
- Steal his dollars;
- Do nothing to him;
- Help him gain political influence, by giving him dollars.
But your services don't come for free. Once you help a politician gain political influence, he is bound to help you cover-up one of your thefts so that you won't get in trouble, for instance, by providing an alibi. In turn, you are also bound to not steal his money in the future.
Initially you start with no money. Your task is to rob as many politicians as possible; however, you can't afford to get caught, so you need a politician to account for each crime you commit.
What is the maximum number of people you can rob?
Input
The first line of the input contains a positive integer (), the number of politicians. The second line of the input contains positive integers (, for all ). The third line of the input contains positive integers (, for all ).
Output
Output a single non-negative integer, the maximum number of people that you can steal from.
Note that you do not have to maximize your own wealth, but rather the number of people that you are stealing from.