fork download
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int t = sc.nextInt();
  8. while (t-- > 0) {
  9. long n = sc.nextLong();
  10. long[] arr = new long[(int) (n + 1)];
  11. for (long i = 1; i <= n; i++) {
  12. arr[(int) i] = sc.nextLong();
  13. }
  14. Arrays.sort(arr, 1, (int) (n + 1));
  15. long median = arr[(int) ((n + 1) / 2)];
  16. long cnt = 0;
  17. for (long i = (n + 1) / 2; i <= n; i++) {
  18. if (arr[(int) i] == median) {
  19. cnt++;
  20. } else {
  21. break;
  22. }
  23. }
  24. System.out.println(cnt);
  25. }
  26. }
  27. }
  28.  
Success #stdin #stdout 0.12s 56596KB
stdin
8
3
2 2 8
4
7 3 3 1
1
1000000000
5
5 5 5 4 5
6
2 1 2 3 1 4
2
1 2
2
1 1
4
5 5 5 5
stdout
1
2
1
3
2
1
2
3