CF1353A Most Unstable Array
题目描述
给定两个整数 $n$ 和 $m$ ,构造一个长度为 $n$ 且每个元素均为非负整数的数组 $a$ ,使得数组内每个元素的和为 $m$ ,且 $\sum \limits_{i=1}^{n-1}|a_i-a_{i+1}|$ 的值尽可能大,输出这个最大值。
输入格式
第一行一个整数 $t$ ,接下来 $t$ 行,每行两个整数 $n,m$ 。
输出格式
对于每组数据,输出题目要求的最大值。
说明/提示
In the first test case of the example, the only possible array is $ [100] $ and the answer is obviously $ 0 $ .
In the second test case of the example, one of the possible arrays is $ [2, 0] $ and the answer is $ |2-0| = 2 $ .
In the third test case of the example, one of the possible arrays is $ [0, 2, 0, 3, 0] $ and the answer is $ |0-2| + |2-0| + |0-3| + |3-0| = 10 $ .