CF1453B Suffix Operations
题目描述
给你一个整数序列,其中有$n$个元素。你需要对这个序列进行操作。
1 在所有操作开始前,你可以选择一个数,并修改他的值,这个值你可以自己定。本操作无花费。
2 选择一个下表$i$,将所有下表不大于$i$的元素加上一个整数$x$,$x$可以你自己定。这次操作花费为$x$的绝对值。
本题给你一个序列,要你求要将这个序列中的元素统一,至少花费多少。
输入格式
第一行一个整数,测试数据数量。
对于每个测试数据,第一行一个整数$n$,元素的个数。接下来一行$n$个整数,为元素的值。
输出格式
对于每组数据,输出最小花费,占一行。
注意,元素值可能为负数或$0$。
说明/提示
In the first case, all elements of the array are already equal. Therefore, we do not change any integer and Gildong will perform zero operations.
In the second case, we can set $ a_3 $ to be $ 0 $ , so that the array becomes $ [-1,0,0] $ . Now Gildong can use the $ 2 $ -nd operation once on the suffix starting at $ a_2 $ , which means $ a_2 $ and $ a_3 $ are decreased by $ 1 $ , making all elements of the array $ -1 $ .
In the third case, we can set $ a_1 $ to $ 96 $ , so that the array becomes $ [96,96,97,95] $ . Now Gildong needs to:
- Use the $ 2 $ -nd operation on the suffix starting at $ a_3 $ once, making the array $ [96,96,96,94] $ .
- Use the $ 1 $ -st operation on the suffix starting at $ a_4 $ $ 2 $ times, making the array $ [96,96,96,96] $ .
In the fourth case, we can change the array into $ [-3,-3,-2,1] $ . Now Gildong needs to:
- Use the $ 2 $ -nd operation on the suffix starting at $ a_4 $ $ 3 $ times, making the array $ [-3,-3,-2,-2] $ .
- Use the $ 2 $ -nd operation on the suffix starting at $ a_3 $ once, making the array $ [-3,-3,-3,-3] $ .