Sky and Pink
InterviewTime limit1sMemory limit1024 MB
Given two lists of positive integers, find nonzero a and b with absolute value at most 1000000 that make |a·sum(A) - b·sum(B)| as small as possible.
- Level
Easy3 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Shihyun found pink hair strands and sky-blue hair strands lying in a corner of his room!
Shihyun was sure that all of them belonged to Danbi.
Shihyun measured the strands. The length of the -th pink strand was , and the length of the -th sky-blue strand was .
After measuring every strand, Shihyun wondered which nonzero integers and , each between and inclusive, minimize .
Answer his question!
Input
The first line contains the number of hair pairs .
The second line contains , and the third line contains , separated by spaces.
All numbers in the input are integers.
Output
On the first line, print and that minimize , separated by a space.
If there are several such pairs , print any of them.