import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int maxarray(int[] arr) { Arrays.sort(arr); return arr[arr.length-1]; } static int minarray(int[] arr) { Arrays.sort(arr); return arr[0]; } static int bworarray(int[] arr) { Arrays.sort(arr); int result = 0; for(int i=0; ij;i--) { int[] subarr = Arrays.copyOfRange(A, j, i); int thiscost = cost(subarr); if((thiscost>lastcost) && (Math.abs(maxcosti-maxcostj)0) { result[j] = lastcost; } else { result[j] = -1; } } //result = Arrays.copyOfRange(A, maxcostj, maxcosti); return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int[] A = new int[n]; for(int A_i = 0; A_i < n; A_i++){ A[A_i] = in.nextInt(); } int[] result = costlyIntervals(n, k, A); for (int i = 0; i < result.length; i++) { System.out.print(result[i] + (i != result.length - 1 ? "\n" : "")); } System.out.println(""); in.close(); } }