K-Anonymous sequence (poj 3709)

Source: Internet
Author: User

Http://poj.org/problem? Id = 3709

Given a non-strictly monotonically incrementing series A1,..., An. Each operation can reduce the value of any item in the series by 1. Now we need to make each item in the series meet at least one of the other items that is equal to its K-1. Calculate the minimum number of operations on this sequence.

Input: number of groups of the first behavior test data t (1 ≤T≤ 20)

Each group of test data contains two rows:

The first behavior is two positive integers n, k. N is the number of elements in the series (2 ≤N≤ 500000 );

The second act is a nonstrictly monotonic increasing number of N integers. The value range of a positive integer is [0, 500000].

Output:

Each group of test data outputs a positive integer, that is, the minimum number of operations on this series.

Sample Input

27 32 2 3 4 4 5 56 20 3 3 4 8 9

Sample output

35

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.