{"problem":{"name":"±1 Operation 2","description":{"content":"You are given a sequence of length $N$: $A=(A_1,A_2,\\dots,A_N)$. The following action on this sequence is called an _operation_. *   First, choose an integer $i$ such that $1 \\le i \\le N$. *   Next, ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc255_d"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence of length $N$: $A=(A_1,A_2,\\dots,A_N)$. The following action on this sequence is called an _operation_.\n\n*   First, choose an integer $i$ such that $1 \\le i \\le N$.\n*   Next, choose and do one of the following.\n    *   Add $1$ to $A_i$.\n    *   Subtract $1$ from $A_i$.\n\nAnswer $Q$ questions.  \nThe $i$\\-th question is the following.\n\n*   Consider performing zero or more operations to change every element of $A$ to $X_i$. Find the minimum number of operations required to do so.\n\n## Constraints\n\n*   All values in input are integers.\n*   $1 \\le N,Q \\le 2 \\times 10^5$\n*   $0 \\le A_i \\le 10^9$\n*   $0 \\le X_i \\le 10^9$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $Q$\n$A_1$ $A_2$ $\\dots$ $A_N$\n$X_1$\n$X_2$\n$\\vdots$\n$X_Q$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc255_d","tags":[],"sample_group":[["5 3\n6 11 2 5 5\n5\n20\n0","10\n71\n29\n\nWe have $A=(6,11,2,5,5)$ and three questions in this input.\nFor the $1$\\-st question, you can change every element of $A$ to $5$ in $10$ operations as follows.\n\n*   Subtract $1$ from $A_1$.\n*   Subtract $1$ from $A_2$ six times.\n*   Add $1$ to $A_3$ three times.\n\nIt is impossible to change every element of $A$ to $5$ in $9$ or fewer operations.\nFor the $2$\\-nd question, you can change every element of $A$ to $20$ in $71$ operations.\nFor the $3$\\-rd question, you can change every element of $A$ to $0$ in $29$ operations."],["10 5\n1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353\n555555555\n321654987\n1000000000\n789456123\n0","3316905982\n2811735560\n5542639502\n4275864946\n4457360498\n\nThe output may not fit into $32$\\-bit integers."]],"created_at":"2026-03-03 11:01:14"}}