def calcular_costo_minimo(positions_initial, positions_target):
costo_total = 0
for pos_inicial, pos_objetivo in zip(positions_initial, positions_target):
costo_total += abs(pos_inicial - pos_objetivo)
return costo_total
def generar_lista_destino_x(N):
destino_x = []
for x in range(1, N + 1):
destino_x.extend([x, x])
return destino_x
def generar_lista_destino_y(N):
destino_y = [1] * N + [2] * N
return destino_y
def main():
import sys
input_data = sys.stdin.read().strip().split()
if not input_data:
return
index = 0
N = int(input_data[index])
index += 1
total_monedas = 2 * N
lista_x = []
lista_y = []
for _ in range(total_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_lista_destino_x(N)
destino_y = generar_lista_destino_y(N)
costo_x = calcular_costo_minimo(lista_x, destino_x)
costo_y = calcular_costo_minimo(lista_y, destino_y)
costo_total = costo_x + costo_y
sys.stdout.write(str(costo_total))
main()
컴파일 시 표준 출력 (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... |