最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF 1847A - The Man who became a God

2023-07-08 10:53 作者:您是打尖兒還是住店呢  | 我要投稿

Kars is tired and resentful of the narrow mindset of his village since they are content with staying where they are and are not trying to become the perfect life form. Being a top-notch inventor, Kars wishes to enhance his body and become the perfect life form. Unfortunately, n

?of the villagers have become suspicious of his ideas. The i-th villager has a suspicion of ai on him. Individually each villager is scared of Kars, so they form into groups to be more powerful.


The power of the group of villagers from l to r be defined as f(l,r) wheref(l,r)=|al?al+1|+|al+1?al+2|+…+|ar?1?ar|.

Here |x?y| is the absolute value of x?y. A group with only one villager has a power of 0.


Kars wants to break the villagers into exactly k contiguous subgroups so that the sum of their power is minimized. Formally, he must find k?1

?positive integers 1≤r1<r2<…<rk?1<n such that f(1,r1)+f(r1+1,r2)+…+f(rk?1+1,n) is minimised.

?Help Kars in finding the minimum value of f(1,r1)+f(r1+1,r2)+…+f(rk?1+1,n).


Input

The first line contains a single integer t (1≤t≤100)

?— the number of test cases. The description of test cases follows.


The first line of each test case contains two integers n,k (1≤k≤n≤100)

?— the number of villagers and the number of groups they must be split into.


The second line of each test case contains n integers a1,a2,…,an (1≤ai≤500)

?— the suspicion of each of the villagers.


Output

For each test case, output a single integer

?— the minimum possible value of sum of power of all the groups i. e. the minimum possible value of f(1,r1)+f(r1+1,r2)+…+f(rk?1+1,n).


Example

input

3

4 2

1 3 5 2

6 3

1 9 12 4 7 2

12 8

1 9 8 2 3 3 1 8 7 7 9 2

output

4

11

2

Note

In the first test case, we will group the villagers with suspicion (1,3,5,2)

?into (1,3,5) and (2). So, f(1,3)+f(4,4)=(|1?3|+|3?5|)+0=4+0=4.


In the second test case, we will group the villagers with suspicion (1,9,12,4,7,2)

?into (1),(9,12),(4,7,2). So, f(1,1)+f(2,3)+f(4,6)=0+3+8=11.

-------------------------------

找相應(yīng)的最小值,就是將差值的絕對值排序,從小大大,選擇即可,看來是一道思維題,我大意了。


CF 1847A - The Man who became a God的評論 (共 條)

分享到微博請遵守國家法律
江油市| 六枝特区| 沿河| 阜新市| 塘沽区| 衡山县| 陆河县| 陆丰市| 正镶白旗| 黄石市| 金山区| 中宁县| 饶阳县| 吉木乃县| 扎囊县| 桦南县| 上杭县| 古田县| 焉耆| 江都市| 卢湾区| 依安县| 英超| 陵水| 乡城县| 潍坊市| 太保市| 商城县| 留坝县| 东台市| 南部县| 九寨沟县| 永州市| 龙川县| 左云县| 衡阳县| 景泰县| 巩留县| 海盐县| 永济市| 西吉县|