BETA

Difficulty Level: Medium

Submissions: 233 Accuracy:

24.46%

Subarray Inversions
     

Given an array A of n integers, find the sum of the number of inversions in all subarrays of length k. To clarify, determine the number of inversions in each of the n – k + 1 subarrays of length k and add them together.

Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case contains two space separated integers n and k. The next line contains a sequence of n space separated integers.

Output:
Print the total number of subarray inversions.

Constraints: 
1<=T<=100
1<=n<=1000
1<=k 1<=a[i]<=100000

Example:
Input:

2
8 4
12 3 14 8 15 1 4 22
10 5
15 51 44 44 76 50 29 88 48 50

Output:
14
25

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Ashtputre

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.