#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5, inf = 0x3f3f3f3f ;
int n, m, d;
struct node
{
int v[maxn];
int w[maxn];
}supplier[maxn];//商人结构体
int sup[maxn];//存储第几件商品找谁买
int tsup[maxn];//暂时存储第几件商品找谁买
int sum, weight;//价值,重量和
int flag = 0;//标志
bool ok(int x, int y, int ts, int tw)
{
if(x <= m && x >= 0 && y <= n && y >= 0 && ts <= d)return true;
else return false;
}//判断函数,确定能从这个人这里买
void fin(int x, int y, int ts, int tw)
{
if(!ok(x,y,ts,tw)) return;//不能买退出
tsup[y] = x;//第y件物品找x买
if(y == n) {//第y件也买完即所有的物品都买了
flag = 1;//标志为1,即true
if(weight > tw) {//tw小于当前最优重量
sum = ts, weight = tw;//更新
for(int i = 1; i <= n; i++){sup[i] = tsup[i];}
}
return;
}
for(int i = 1; i <= m; i++){//继续搜索下一层
fin(i,y+1,ts + supplier[i].v[y+1] ,tw + supplier[i].w[y+1]);
}
}
int main()
{
printf("请输入三个数,代表n,m,d,即部件数,供应商数目和最大价格\n");
scanf("%d%d%d",&n,&m,&d);
sum = d, weight = inf;
printf("请输入相应的价格\n");
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d",&supplier[j].v[i]);
printf("请输入相应的重量\n");
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d",&supplier[j].w[i]);
fin(1,1,supplier[1].v[1] ,supplier[1].w[1]);//第i件物品找谁买
cout<<weight<<endl;
if(flag){
for(int i = 1; i <= n; i++)
cout<<sup[i]<<" ";
cout<<endl;
}
else cout<<"No\n"<<endl;
}
/*
3 3 4
1 2 3
3 2 1
2 2 2
1 2 3
3 2 1
2 2 2
*/