#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long a[N];
bool cmp(int i, int j)
{
return a[i] > a[j];
}
int main() {
int n, p, k;
cin >> n >> p >> k;
long long skills[n][p];
long long dp[n + 1][1 << p];
memset(dp, -1, sizeof dp);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < p; j++)
{
cin >> skills[i][j];
}
}
int ind[n];
for(int i = 0; i < n; i++)
{
ind[i] = i;
}
sort(ind, ind + n, cmp);
dp[0][0] = 0;
for(int i = 0; i < n; i++)
{
int x = ind[i];
for(long long mask = 0; mask < (1 << p); mask++)
{
if(dp[i][mask] == -1)
{
continue;
}
int inaud = i - __builtin_popcount(mask);
if(inaud < k)
{
dp[i + 1][mask] = max(dp[i + 1][mask], dp[i][mask] + a[x]);
}
else
{
dp[i + 1][mask] = max(dp[i + 1][mask], dp[i][mask]);
}
for(int j = 0; j < p; j++)
{
if(((mask & (1 << j)) == 1) and (dp[i][mask ^ (1 << j)] != -1))
{
dp[i + 1][mask] = max(dp[i + 1][mask], dp[i][mask ^ (1 << j)] + skills[x][j]);
}
else if(((mask & (1 << j)) == 0))
{
dp[i + 1][mask | (1 << j)] = max(dp[i + 1][mask | (1 << j)], dp[i][mask] + skills[x][j]);
}
}
cout << i + 1 << " " << mask << "\n";
for(int j = 0; j < (1 << p); j++)
{
cout << dp[i + 1][j] << " ";
}
cout << "\n";
}
}
cout << dp[n][(1 << p) - 1];
return 0;
}
/* 6 2 3
93 78 78 17 13 9
30 52
80 97
84 55
56 68
60 36
26 17 */
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDEwMDAwNTsKbG9uZyBsb25nIGFbTl07Cgpib29sIGNtcChpbnQgaSwgaW50IGopCnsKCXJldHVybiBhW2ldID4gYVtqXTsKfQoKaW50IG1haW4oKSB7CglpbnQgbiwgcCwgazsKCWNpbiA+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