Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
1.2 kB
4
Indexable
Never
import java.util.*;

public class MaxnessOfSubarrays {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while (t-- > 0) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int[] A = new int[n];
            for (int i = 0; i < n; i++) {
                A[i] = scanner.nextInt();
            }
            int[] maxnessArray = findMaxnessOfSubarrays(A, n, m);
            for (int maxness : maxnessArray) {
                System.out.print(maxness + " ");
            }
            System.out.println();
        }
        scanner.close();
    }

    private static int[] findMaxnessOfSubarrays(int[] A, int n, int m) {
        int[] maxnessArray = new int[n - m + 1];
        for (int i = 0; i <= n - m; i++) {
            int maxness = 0;
            for (int j = i + 1; j < i + m; j++) {
                for (int k = 0; k < i; k++) {
                    if (A[j] * A[i] > A[k]) {
                        maxness++;
                    }
                }
            }
            maxnessArray[i] = maxness;
        }
        return maxnessArray;
    }
}