P10747 [SEERC 2020] Neo-Robin Hood

Description

You are a thief. There are $n$ households in the town. For each household $i$, you choose one of the following options. - Steal $m_i$ dollars from them, and they will start hating you. - Give them $p_i$ dollars, and they will make one person you have stolen from cancel their hatred toward you. - Do nothing. Initially, you have no money. You want to know: while ensuring that nobody hates you and the amount of money you have is non-negative, what is the maximum number of households you can steal from. Note: You may visit the households one by one in any order.

Input Format

The first line contains an integer $n\ (1 \leq n \leq 10^5)$. The second line contains a sequence $m$ of length $n$ $(1 \leq m_i \leq 10^9)$. The third line contains a sequence $p$ of length $n$ $(1 \leq p_i \leq 10^9)$.

Output Format

Output the maximum number of households you can steal from.

Explanation/Hint

Translated by ChatGPT 5