fork download
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class QueriesAboutLessOrEqual {
  5.  
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. int n = sc.nextInt();
  10. int m = sc.nextInt();
  11.  
  12. int[] a = new int[n];
  13. int[] b = new int[m];
  14.  
  15. for (int i = 0; i < n; ++i) {
  16. a[i] = sc.nextInt();
  17. }
  18.  
  19. for (int i = 0; i < m; ++i) {
  20. b[i] = sc.nextInt();
  21. }
  22.  
  23. Arrays.sort(a);
  24. for (int i = 0; i < m; ++i) {
  25. sb.append(binarySearchGreater(a, b[i]));
  26. sb.append(" ");
  27. }
  28. System.out.println(sb);
  29. }
  30.  
  31. private static int binarySearchGreater(int[] a, int val) {
  32.  
  33. int start = 0;
  34. int end = a.length;
  35. int middle = 0;
  36.  
  37. while (start < end) {
  38. middle = start + (end - start) / 2;
  39. if (a[middle] == val) {
  40. if (middle + 1 >= a.length || a[middle + 1] > val) {
  41. return middle + 1;
  42. }
  43. start = middle + 1;
  44.  
  45. }
  46. else if (val > a[middle]) {
  47. start = middle + 1;
  48. }
  49. else {
  50. end = middle;
  51. }
  52. }
  53.  
  54. if (a[middle] > val) {
  55. return middle;
  56. }
  57. return middle + 1;
  58. }
  59.  
  60. }
  61.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: class QueriesAboutLessOrEqual is public, should be declared in a file named QueriesAboutLessOrEqual.java
public class QueriesAboutLessOrEqual {
       ^
1 error
stdout
Standard output is empty