Jarvis
InterviewTime limit1sMemory limit512 MB
Pick one integer X added to every factory frequency so that the count of indices with Ai + X = Bi is as large as possible.
- Level
Medium4 of 10
- Topics
- Hash map, Array, Implementation, Greedy
- Solved
- No attempts yet
Problem
Ivan sent N drone warriors to the final battle against Tony Stark, also known as Iron Man. Each drone has a frequency, given as an integer, on which it receives commands from Ivan during the fight. Jarvis, the artificial intelligence developed by Tony, has to determine those frequencies and take control of as many drones as possible.
Jarvis knows the original factory frequency value of each drone, but the frequency each drone requires has been changed in the meantime.
Jarvis has only one attempt. He can choose an integer X and increase every factory frequency by X (X may be negative). After that, Jarvis takes control of every drone whose modified factory frequency equals the frequency that drone requires.
Write a program that determines the largest number of drone warriors Jarvis can take control of.
Input
The first line contains the integer N (1 ≤ N ≤ 100 000), the number of drones from the statement.
The second line contains N integers Ai (-1 000 000 ≤ Ai ≤ 1 000 000) representing the factory frequency values of the drone warriors.
The third line contains N integers Bi (-1 000 000 ≤ Bi ≤ 1 000 000) representing the required frequency values of the drone warriors.
Output
On a single line, print the largest number of drone warriors Jarvis can take control of.