Untitled
unknown
plain_text
2 years ago
1.5 kB
5
Indexable
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Solution {
static int m, k, n, min, count;
static int[] voi = new int[19];
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
System.setIn(new FileInputStream("src/input.txt"));
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int t = 1; t <= T; t++) {
n = sc.nextInt();
k = sc.nextInt();
m = sc.nextInt();
for (int i = 1; i <= n; i++) {
voi[i] = sc.nextInt();
}
min = 20;
count = 0;
checkVoi(1);
if(min==20){
min=-1;
}
System.out.println("#"+t+" "+ min);
}
sc.close();
}
private static void checkVoi(int x) {
// TODO Auto-generated method stub
if (check()) {
min = count < min ? count : min;
}
if (count > min)
return;
if (x == n + 1) {
return;
}
for (int i = 0; i < 2; i++) {
if (i == 0) {
voi[x]++;
count++;
checkVoi(x + 1);
count--;
voi[x]--;
} else {
checkVoi(x + 1);
}
}
}
private static boolean check() {
// TODO Auto-generated method stub
for (int i = 1; i <= n-k+1; i++) {
int max = 0;
for (int j = i; j < i + k; j++) {
if (max < voi[j]) {
max = voi[j];
}
}
int cnt = 0;
for (int j = i; j < i + k; j++) {
if (voi[j] == max) {
cnt++;
}
}
if (cnt >= m) {
return false;
}
}
return true;
}
}
Editor is loading...