def calcular_costo_minimo(lista_inicial, lista_destino):
costo = 0
for valor_inicial, valor_destino in zip(lista_inicial, lista_destino):
costo += abs(valor_inicial - valor_destino)
return costo
def generar_destino_x(N):
destino_x = []
for x in range(1, N + 1):
destino_x.append(x)
destino_x.append(x)
return destino_x
def generar_destino_y(N):
return [1] * N + [2] * N
def main():
import sys
input_data = sys.stdin.read().split()
if not input_data:
return
index = 0
N = int(input_data[index])
index += 1
num_monedas = 2 * N
lista_x = []
lista_y = []
for _ in range(num_monedas):
x = int(input_data[index])
y = int(input_data[index + 1])
index += 2
lista_x.append(x)
lista_y.append(y)
lista_x.sort()
lista_y.sort()
destino_x = generar_destino_x(N)
destino_y = generar_destino_y(N)
costo_x = calcular_costo_minimo(lista_x, destino_x)
costo_y = calcular_costo_minimo(lista_y, destino_y)
resultado = costo_x + costo_y
sys.stdout.write(str(resultado))
main()
Compilation message (stdout)
Compiling 'joi2019_ho_t4.py'...
=======
adding: __main__.pyc (deflated 45%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |