#C9583. Minimum Challenge Completion Time

    ID: 53692 Type: Default 1000ms 256MiB

Minimum Challenge Completion Time

Minimum Challenge Completion Time

You are given a contest with N rounds and M challenges in each round. Each challenge in round i has a required skill level denoted by Di,j and takes a time of Ti,j to solve.

A participant with skill S can only attempt a challenge in round i if S \ge Di,j. In each round, the participant must choose exactly one challenge that they are capable of solving. The objective is to calculate the minimum total time required to complete all rounds. If there is some round in which no challenge can be attempted, the output should be -1.

The mathematical formulation for the total time is:

\[ \text{Total Time} = \sum_{i=1}^{N} \min_{\{j \mid S \ge D_{i,j}\}} T_{i,j} \]

If for any round i there is no challenge j such that \(S \ge D_{i,j}\), then the answer is -1.

inputFormat

The input is given via stdin and has the following format:

N M S
D1,1 D1,2 ... D1,M
D2,1 D2,2 ... D2,M
... 
DN,1 DN,2 ... DN,M
T1,1 T1,2 ... T1,M
T2,1 T2,2 ... T2,M
... 
TN,1 TN,2 ... TN,M

Here, the first line contains three integers N (the number of rounds), M (the number of challenges per round), and S (the skill level of the participant). The next N lines each contain M integers representing the difficulty matrix D. The following N lines each contain M integers representing the time matrix T.

outputFormat

Output a single integer on stdout: the minimum total time required to complete the contest. If it is impossible to select a challenge for any round, output -1.

## sample
3 3 5
1 6 3
7 8 2
4 3 1
2 9 6
3 5 4
5 2 8
8