Many Easy Optimizations

AtCoder
IDarc187_d
Time5000ms
Memory256MB
Difficulty
Define the **cost** of a sequence $X$ as (the maximum value of $X$ minus the minimum value of $X$). You are given sequences $A = (A_1, \ldots, A_N)$ and $B = (B_1, \ldots, B_N)$ of length $N$. Solve the following problem for $k = 1, 2, \ldots, N$. * Find the minimum possible cost of the sequence $C = (C_1, \ldots, C_k)$ whose $i$\-th element $C_i$ is $A_i$ or $B_i$. ## Constraints * All input numbers are integers. * $1 \leq N \leq 5 \times 10^5$ * $1 \leq A_i, B_i \leq 10^9$ ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ $B_1$ $\ldots$ $B_N$ [samples]
Samples
Input #1
3
8 11 10
7 6 1
Output #1
0
1
3

For $k=1$, if we choose $C = (8)$, the cost of $C$ is $0$, which is the minimum.
For $k=2$, if we choose $C = (7,6)$, the cost of $C$ is $1$, which is the minimum.
For $k=3$, if we choose $C = (8,11,10)$, the cost of $C$ is $3$, which is the minimum.
Input #2
10
43 35 36 58 25 7 61 4 96 3
55 29 88 15 99 49 67 57 92 49
Output #2
0
8
8
23
28
33
36
36
64
64
API Response (JSON)
{
  "problem": {
    "name": "Many Easy Optimizations",
    "description": {
      "content": "Define the **cost** of a sequence $X$ as (the maximum value of $X$ minus the minimum value of $X$). You are given sequences $A = (A_1, \\ldots, A_N)$ and $B = (B_1, \\ldots, B_N)$ of length $N$. Solve t",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc187_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Define the **cost** of a sequence $X$ as (the maximum value of $X$ minus the minimum value of $X$).\nYou are given sequences $A = (A_1, \\ldots, A_N)$ and $B = (B_1, \\ldots, B_N)$ of length $N$. Solve t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments