█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2772

Problema 0x62 - Contar elementos mayores a X en un arreglo pequeño

  • Autor: hamorillo
  • Fecha: 2021-02-04 14:35:17 UTC (Hace casi 4 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.171 s 16 KBi
#2
Incorrecto
0.194 s 22 KBi
#3
Correcto
0.173 s 16 KBi
#4
Correcto
0.168 s 16 KBi
#5
Incorrecto
0.157 s 15 KBi
#6
Correcto
0.197 s 22 KBi
#7
Incorrecto
0.214 s 25 KBi
#8
Incorrecto
0.191 s 16 KBi
#9
Correcto
0.216 s 16 KBi
#10
Correcto
0.223 s 20 KBi
Puntos totales: 50 / 100

Código

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Data data = readNumsFromStdin();

        Arrays.sort(data.numbers);

        for (int i = 0; i < data.totalRequest; i++) {
            for (int j = 0; j < data.totalNumbers; j++) {
                if (data.numbers[j] > data.request[i]) {
                    System.out.println(data.totalNumbers - j);
                    break;
                }
            }
        }
    }

    private static Data readNumsFromStdin() {
        Data data = new Data();
        Scanner in = new Scanner(System.in);

        data.totalNumbers = in.nextInt();
        data.numbers = new int[data.totalNumbers];
        readArrayFromStdin(data.numbers, data.totalNumbers, in);

        data.totalRequest = in.nextInt();
        data.request = new int[data.totalRequest];
        readArrayFromStdin(data.request, data.totalRequest, in);
        return data;
    }

    private static void readArrayFromStdin(int[] array, int count, Scanner in) {
        for (int i = 0; i < count; i++) {
            array[i] = in.nextInt();
        }
    }

    private static class Data {
        int totalNumbers;
        int[] numbers;
        int totalRequest;
        int[] request;
    }
}