cswork / OAOpen practice workspace

CloudflareOA #1

Determine Minimum Partitions Required

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

Each partition has a capacity and a used amount, and data may be split into chunks and moved to other partitions. Find the minimum number of partitions that must be kept to hold all existing data; data in an original partition does not have to be moved as a whole.

Input

The first line contains n, the second line contains n capacities, and the third line contains n used amounts. The original had no numeric bounds; this site adds 1≤n≤200000, capacities 1..10^9, and 0≤used[i]≤capacity[i]. When the total usage is 0, this site explicitly outputs 0.

Output

Output a single integer, the answer.

Example 1

Input:

4
10 15 15 20
5 10 15 5

Output:

2

Example 2

Input:

2
2 9
0 0

Output:

0

Example 3

Input:

2
2 9
2 2

Output:

1

Example notes

The outputs of the three public examples are, in order: 2; 0; 1. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…