Alawn's Problem

View as PDF

Submit solution

Points: 7
Time limit: 3.0s
Memory limit: 256M

Author:
Problem type

Alawn has a length N array of pairs (ai,bi). Initially, ai=bi for all i.

Alawn loves arrays that satisfy the following property:

  • The a values can be sorted by only swapping elements i and j where bi×bjV.

A modification to the array consists of decreasing element i's bi value by 1. Can you determine the minimum number of modifications required to turn the array of pairs into one that Alawn loves?

Input Specification

The first line will contain T (1T10), the number of test cases. T test cases follow.

For each test case, the first line will contain two integers N,V (1N105,1V1018), the number of elements in the array and the special value V.

The second line will contain N integers, ai (1ai109), the elements of the array. Recall that ai=bi initially.

Output Specification

For each case, output the minimum number of modifications required on its own line.

Sample Input

Copy
2
5 1
1 2 3 4 5
5 4
1 2 5 3 6

Sample Output

Copy
0
1

Comments

There are no comments at the moment.