# Poj Solution 3125

```http://poj.org/problem?id=3125

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

/**
* @author NC
* poj3125
*/
public class Main {

public static void main(String[] args) {

Scanner scan = new Scanner(new BufferedInputStream(System.in));
int cas = scan.nextInt();
for (int i = 1; i <= cas; i++) {
int n = scan.nextInt();
int position = scan.nextInt();
int[] priority = new int[n];
for (int j = 0; j < n; j++) {
priority[j] = scan.nextInt();
}
Arrays.sort(priority);//非递减的
int time = 0;
int count = priority.length - 1;
Job current = null;
do {
current = queue.getFirst();
if (current.priority < priority[count]) {
current = queue.removeFirst();
} else if (current.priority == priority[count]) {
time++;
count--;
queue.removeFirst();
if (current.number == position + 1) {
break;
}
} else {
System.out.println("error");
}
} while (true);
System.out.println(time);
}
}
}

class Job {

int priority;
int number;

Job(int n, int p) {
this.priority = p;
this.number = n;
}
}

```
This entry was posted in poj. Bookmark the permalink.