#include <bits/stdc++.h>   using namespace std;   long long c[105], x[105][105], dp[105][105][105];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k, i, j, l, p, ans = 10000000000000000;     cin >> n >> m >> k;     for (i = 1; i <= n; i++) cin >> c[i];     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) cin >> x[i][j];     for (i = 0; i <= 100; i++)       for (j = 0; j <= 100; j++)         for (l = 0; l <= 100; l++) dp[i][j][l] = 10000000000000000;     if (c[1] == 0) {       for (i = 1; i <= m; i++) dp[1][1][i] = x[1][i];     } else       dp[1][1][c[1]] = 0;     for (i = 2; i <= n; i++) {       if (c[i] == 0) {         for (p = 1; p <= k; p++) {           for (j = 1; j <= m; j++) {             for (l = 1; l <= m; l++) {               if (j == l) {                 dp[i][p][l] = min(dp[i][p][l], dp[i - 1][p][j] + x[i][l]);               } else {                 dp[i][p + 1][l] = min(dp[i][p + 1][l], dp[i - 1][p][j] + x[i][l]);               }             }           }         }       } else {         for (p = 1; p <= k; p++) {           for (j = 1; j <= m; j++) {             if (j == c[i]) {               dp[i][p][c[i]] = min(dp[i][p][c[i]], dp[i - 1][p][j]);             } else {               dp[i][p + 1][c[i]] = min(dp[i][p + 1][c[i]], dp[i - 1][p][j]);             }           }         }       }     }     if (c[n] == 0) {       for (i = 1; i <= m; i++) ans = min(ans, dp[n][k][i]);     } else       ans = dp[n][k][c[n]];     if (ans != 10000000000000000)       cout << ans;     else       cout << -1;     return 0;   }   