fork download
  1. import java.util.*
  2.  
  3. data class Task(val num: Int, val priority: Int)
  4.  
  5. fun main() {
  6. val sc = Scanner(System.`in`)
  7. val cnt = sc.nextLine().toInt()
  8.  
  9. val sb = StringBuilder()
  10. repeat(cnt) {
  11. val pq = PriorityQueue<Task>(compareBy({ -it.priority }, { it.num }))
  12. val (n, m) = sc.nextLine().split(" ").map { it.toInt() }
  13. val token = StringTokenizer(sc.nextLine())
  14.  
  15. repeat(n) {
  16. pq.add(Task(num = it, priority = token.nextToken().toInt()))
  17. }
  18.  
  19. val current = 1
  20. while (pq.isNotEmpty()) {
  21. if (pq.poll().num == m) {
  22. sb.append(current).append("\n")
  23. break
  24. }
  25. }
  26. }
  27.  
  28. println(sb)
  29. }
  30.  
Success #stdin #stdout 0.14s 42828KB
stdin
3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1
stdout
1
1
1