J. Bashar and daylight saving time

Codeforces
IDCF10216J
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
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. The first line contains number of test cases $T$. Each test case starts with a line containing two integers: $N, M$ $(1 <= M <= N <= 10^5)$. Followed by two lines, first line contains $M$ space separated integers, Where $A_i$ is the time that the $i_{t h}$ 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 <= A_i <= N$, $-N <= X_i <= N$ 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. ## Input The first line contains number of test cases $T$.Each test case starts with a line containing two integers: $N, M$ $(1 <= M <= N <= 10^5)$. Followed by two lines, first line contains $M$ space separated integers, Where $A_i$ is the time that the $i_{t h}$ 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 <= A_i <= N$, $-N <= X_i <= 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. [samples]
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case: - Let $ N, M \in \mathbb{Z} $ with $ 1 \leq M \leq N \leq 10^5 $. - Let $ A = (A_1, A_2, \dots, A_M) $ be the initial clock times, where $ A_i \in \{1, 2, \dots, N\} $. - Let $ X = (X_1, X_2, \dots, X_M) $ be the time adjustments, where $ X_i \in \{-N, \dots, N\} $. - Define the final time for student $ i $ as $ B_i = ((A_i + X_i - 1) \bmod N) + 1 $, mapping the result to the range $[1, N]$. **Constraints** 1. $ 1 \leq T \leq \text{unknown} $ (implied by input format). 2. $ 1 \leq M \leq N \leq 10^5 $. 3. $ 1 \leq A_i \leq N $. 4. $ -N \leq X_i \leq N $. **Objective** For each test case, compute the frequency of each hour $ h \in \{1, 2, \dots, N\} $ in the multiset $ \{B_1, B_2, \dots, B_M\} $. Let $ f(h) = |\{i \in \{1, \dots, M\} \mid B_i = h\}| $. Find $ h^* = \min \{ h \in \{1, \dots, N\} \mid f(h) = \max_{1 \leq j \leq N} f(j) \} $, and output $ h^* $ and $ f(h^*) $.
API Response (JSON)
{
  "problem": {
    "name": "J. Bashar and daylight saving time",
    "description": {
      "content": "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'",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10216J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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.\n\nThere are $M$ students at NCD. Each student'...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case:  \n- Let $ N, M \\in \\mathbb{Z} $ with $ 1 \\leq M \\leq N \\leq 10^5 $.  \n- Let $ A = (A_1, A_2, \\dots, A_M) $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments