#P10747. [SEERC 2020] Neo-Robin Hood

[SEERC 2020] Neo-Robin Hood

Problem Description

You are a thief. There are nn households in the town. For each household ii, you choose one of the following options.

  • Steal mim_i dollars from them, and they will start hating you.

  • Give them pip_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 (1n105)n\ (1 \leq n \leq 10^5).

The second line contains a sequence mm of length nn (1mi109)(1 \leq m_i \leq 10^9).

The third line contains a sequence pp of length nn (1pi109)(1 \leq p_i \leq 10^9).

Output Format

Output the maximum number of households you can steal from.

5
2 3 4 5 6
1 2 3 4 5
2
4
1 2 4 2
5 6 9 7

0
4
9 19 6 5
20 3 16 19

1

Hint

Translated by ChatGPT 5