#P1252. Marathon Relay Optimization
Marathon Relay Optimization
Marathon Relay Optimization
A city is hosting a winter relay marathon with a total distance of $25\,\rm{km}$. Each team consists of 5 members and each member must run exactly once. The distance run by each member must be an integer between $1\,\rm{km}$ and $10\,\rm{km}$, and the relay exchange takes place at integer kilometer marks.
For each team member, tests have been conducted to record the time required to run continuously for $1\,\rm{km}$, $2\,\rm{km}$, \dots, $10\,\rm{km}$. In other words, for the i-th runner, you are given 10 integers $t_i(1), t_i(2), \dots, t_i(10)$, where $t_i(d)$ represents the time taken by that runner to run $d\,\rm{km}$ continuously.
The athletes typically run slower for longer continuous distances. That is, for each runner and for any two distances $d_1$ and $d_2$ with $1 \le d_1 < d_2 \le 10$, it holds that $t_i(d_1) \le t_i(d_2)$ (note that the time may remain the same for some distances, but it will never decrease).
Your task is to assign each runner a running distance $d_i$ (where $1 \le d_i \le 10$ for $i=1,2,3,4,5$) such that the total distance is exactly $25\,\rm{km}$ and the total time
$$T = \sum_{i=1}^{5} t_i(d_i)$$
is minimized. It is guaranteed that the minimum total time is unique, although the assignment of distances achieving that minimum might not be unique.
Input details and constraints are described below. Write a program that computes the minimum total time.
inputFormat
The input consists of 5 lines. The i-th line contains 10 space-separated positive integers, representing $t_i(1)$, $t_i(2)$, \dots, $t_i(10)$ for the i-th runner.
outputFormat
Output a single integer representing the minimum total time for the team to complete the $25\,\rm{km}$ relay.
sample
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
25