405934: GYM102163 J Bashar and daylight saving time

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Bashar and daylight saving timetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Last week, the time was changed so that there will be more daylight time. However students in NCD went insane and didn't know how much to change the time.

There are $$$M$$$ students at NCD. Each student's clock was set on a number between $$$1$$$ and $$$N$$$ before the time change. When the change happened, each student $$$i$$$ changed his clock from its original time $$$A_i$$$ to a new time $$$A_i$$$ + $$$X_i$$$. Bashar wants to restore balance and find the correct time. He realized that the correct time is the most visited hour in all the students' clocks. Because he has exams and he is busy, he asked you to find the correct time.

For example, if $$$N$$$ = $$$3$$$ and there are two students, one at $$$1$$$ o'clock and moved the clock $$$+1$$$ (to $$$2$$$ o'clock) and one at $$$3$$$ o'clock and moved his clock $$$+1$$$ (to $$$1$$$ o'clock) then the correct time is $$$1$$$ o'clock, because it was visited two times.

Input

The first line contains number of test cases $$$T$$$.

Each test case starts with a line containing two integers: $$$N, M$$$ $$$(1 \le M \le N \le 10^5)$$$.

Followed by two lines, first line contains $$$M$$$ space separated integers, Where $$$A_i$$$ is the time that the $$$i_{th}$$$ student has set his clock at.

Second line contain $$$M$$$ space separated integers $$$X_i$$$ the number given in the statement. Negative values of $$$X_i$$$ means you should move counter clockwise, positive values of $$$X_i$$$ means you should move clockwise.

$$$ 1 \le A_i \le N$$$, $$$ -N \le X_i \le N$$$

Output

For each test case, print two space separated integers. The number of the most visited hour and how many students visited it.

If there are multiple answers for the number of the hour, print the smallest one.

ExampleInput
1
5 5
1 2 3 4 5
1 1 1 1 2
Output
2 3

Source/Category

加入题单

算法标签: