#abc255d. D - ±1 Operation 2

D - ±1 Operation 2

Score : 400400 points

问题描述

给定一个长度为 NN 的序列:A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N)。以下对该序列的操作被称为 操作

  • 首先,选择一个整数 ii,满足 1iN1 \le i \le N
  • 接着,选择并执行以下操作之一:
    • AiA_i 加上 11
    • AiA_i 减去 11

回答 QQ 个问题。 第 ii 个问题是:

  • 考虑执行零次或多次操作以将 AA 中的所有元素变为 XiX_i。找出完成此目标所需的最少操作次数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N). The following action on this sequence is called an operation.

  • First, choose an integer ii such that 1iN1 \le i \le N.
  • Next, choose and do one of the following.
    • Add 11 to AiA_i.
    • Subtract 11 from AiA_i.

Answer QQ questions. The ii-th question is the following.

  • Consider performing zero or more operations to change every element of AA to XiX_i. Find the minimum number of operations required to do so.

Constraints

  • All values in input are integers.

  • 1N,Q2×1051 \le N,Q \le 2 \times 10^5

  • 0Ai1090 \le A_i \le 10^9

  • 0Xi1090 \le X_i \le 10^9

    20%20\% 的数据, 1N,Q10001 \le N, Q \le 1000

Input

Input is given from Standard Input in the following format:

NN QQ

A1A_1 A2A_2 \dots ANA_N

X1X_1

X2X_2

\vdots

XQX_Q

Output

Print QQ lines. The ii-th line should contain the answer to the ii-th question as an integer.

Sample Input 1

5 3
6 11 2 5 5
5
20
0

Sample Output 1

10
71
29

We have A=(6,11,2,5,5)A=(6,11,2,5,5) and three questions in this input.

For the 11-st question, you can change every element of AA to 55 in 1010 operations as follows.

  • Subtract 11 from A1A_1.
  • Subtract 11 from A2A_2 six times.
  • Add 11 to A3A_3 three times.

It is impossible to change every element of AA to 55 in 99 or fewer operations.

For the 22-nd question, you can change every element of AA to 2020 in 7171 operations.

For the 33-rd question, you can change every element of AA to 00 in 2929 operations.

Sample Input 2

10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0

Sample Output 2

3316905982
2811735560
5542639502
4275864946
4457360498

The output may not fit into 3232-bit integers.

update @ 2024/3/10 10:51:40

}