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

Envío 3602

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

  • Autor: jocarmp08
  • Fecha: 2021-04-03 21:06:37 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.021 s 3 KBi
#2
Incorrecto
0.027 s 3 KBi
#3
Correcto
0.022 s 3 KBi
#4
Correcto
0.017 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    count_elements_greather_than_x(array, queries)
  File "script.py", line 8, in count_elements_greather_than_x
    if array[x_index] == x:
IndexError: list index out of range
0.028 s 3 KBi
#6
Incorrecto
0.024 s 3 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    count_elements_greather_than_x(array, queries)
  File "script.py", line 8, in count_elements_greather_than_x
    if array[x_index] == x:
IndexError: list index out of range
0.046 s 8 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    count_elements_greather_than_x(array, queries)
  File "script.py", line 8, in count_elements_greather_than_x
    if array[x_index] == x:
IndexError: list index out of range
0.025 s 3 KBi
#9
Incorrecto
0.027 s 3 KBi
#10
Incorrecto
0.027 s 3 KBi
Puntos totales: 30 / 100

Código

import bisect


def count_elements_greather_than_x(array, queries):
    array.sort()
    for x in queries:
        x_index = bisect.bisect_left(array, x)
        if array[x_index] == x:
            print(len(array) - x_index - 1)
        else:
            if x < array[x_index]:
                print(len(array))
            else:
                print(0)


array_size = int(input())
array = [int(x) for x in input().split()]
number_of_queries = int(input())
queries = [0 for _ in range(number_of_queries)]

for i in range(number_of_queries):
    queries[i] = int(input())

count_elements_greather_than_x(array, queries)