{"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 the following problem for $k = 1, 2, \\ldots, N$.\n\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$.\n\n## Constraints\n\n*   All input numbers are integers.\n*   $1 \\leq N \\leq 5 \\times 10^5$\n*   $1 \\leq A_i, B_i \\leq 10^9$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ \n$A_1$ $\\ldots$ $A_N$\n$B_1$ $\\ldots$ $B_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc187_d","tags":[],"sample_group":[["3\n8 11 10\n7 6 1","0\n1\n3\n\nFor $k=1$, if we choose $C = (8)$, the cost of $C$ is $0$, which is the minimum.\nFor $k=2$, if we choose $C = (7,6)$, the cost of $C$ is $1$, which is the minimum.\nFor $k=3$, if we choose $C = (8,11,10)$, the cost of $C$ is $3$, which is the minimum."],["10\n43 35 36 58 25 7 61 4 96 3\n55 29 88 15 99 49 67 57 92 49","0\n8\n8\n23\n28\n33\n36\n36\n64\n64"]],"created_at":"2026-03-03 11:01:14"}}