B. Serval and Toy Bricks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.

He has a special interest to create difficult problems for others to solve. This time, with many 1×1×11×1×1 toy bricks, he builds up a 3-dimensional object. We can describe this object with a n×mn×m matrix, such that in each cell (i,j), there are hi,jhi,j bricks standing on the top of each other.

However, Serval doesn't give you any hi,j and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are mm columns, and in the ii -th of them, the height is the maximum of h1,i,h2,i,…,hn,ih1,i,h2,i,…,hn,i . It is similar for the left view, where there are nn columns. And in the top view, there is an n×mn×m matrix ti,jti,j , where ti,jti,j is 00 or 11 . If ti,jti,j equals 11 , that means hi,j>0hi,j>0 , otherwise, hi,j=0hi,j=0 .

However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?

Input

The first line contains three positive space-separated integers n,m,hn,m,h (1≤n,m,h≤1001≤n,m,h≤100 ) — the length, width and height.

The second line contains mm non-negative space-separated integers a1,a2,…,ama1,a2,…,am , where aiai is the height in the ii -th column from left to right of the front view (0≤ai≤h0≤ai≤h ).

The third line contains nn non-negative space-separated integers b1,b2,…,bnb1,b2,…,bn (0≤bj≤h0≤bj≤h ), where bjbj is the height in the jj -th column from left to right of the left view.

Each of the following nn lines contains mm numbers, each is 00 or 11 , representing the top view, where jj -th number of ii -th row is 11 if hi,j>0hi,j>0 , and 00 otherwise.

It is guaranteed that there is at least one structure satisfying the input.

Output

Output nn lines, each of them contains mm integers, the jj -th number in the ii -th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.

Examples
Input

 
3 7 3
2 3 0 0 2 0 1
2 1 3
1 0 0 0 1 0 0
0 0 0 0 0 0 1
1 1 0 0 0 0 0
Output

 
1 0 0 0 2 0 0
0 0 0 0 0 0 1
2 3 0 0 0 0 0
Input

 
4 5 5
3 5 2 0 4
4 2 5 4
0 0 0 0 1
1 0 1 0 0
0 1 0 0 0
1 1 1 0 0
Output

 
0 0 0 0 4
1 0 2 0 0
0 5 0 0 0
3 4 1 0 0




解题思路:这道题就是给你正视图,侧视图,俯视图,让你恢复它的原状;
实际上这个用多组解;用贪心即可,每次取最小;
代码如下:
 #include<iostream>
using namespace std; int row , col , height ;
int c[];
int r[];
int G[][];
int main()
{
cin>>row>>col>>height;
for(int i = ; i < col ;i++)
{
cin>>c[i];
}
for(int i = ; i < row ;i++)
{
cin>>r[i];
} for(int i = ; i < row ;i++)
{
for(int j = ; j < col ;j++)
{
cin>>G[i][j];
if(G[i][j]==)
{
if(c[j]<=r[i]) //不断取行和列交接处的较小者
{
G[i][j] = c[j];
}else
G[i][j] = r[i];
}
}
} for(int i = ; i < row ;i++)
{
for(int j = ; j < col ;j++)
{
cout<<G[i][j];
(j==col-)?cout<<"":cout<<" ";//格式
}
cout<<endl;
}
return ;
}

最新文章

  1. 编程语言吉祥物之Duke
  2. ES6(五) 数组扩展
  3. emmet插件学习,练习中遇到一些问题
  4. Retrofit2 + OkHttp3设置Http请求头(Headers)方法汇总
  5. C结构体之位域(位段)
  6. NOIP2014 联合权值
  7. visual studio问题集合
  8. Webpack 2 视频教程 009 - 配置 ESLint 实现代码规范自动测试 (上)
  9. 闪付卡(QuickPass)隐私泄露原理
  10. 面试linux运维一定会问到Shell脚本这24个问题
  11. spring ,springmvc的常用标签注解
  12. 关于vs2010开发的ASP项目部署到XPSP2系统上出现找不到Reportviewer.XX.文件的解决方案
  13. 每天一个linux命令: /etc/group文件详解
  14. static笔记
  15. Java集合类相关面试题
  16. WEB-INF下资源访问问题
  17. bootstrap自定义——栅格列数修改
  18. JavaScript 初学备忘录
  19. IOS 公司标示和方向域名
  20. 水题:51Nod1432-独木舟

热门文章

  1. U-boot分析与移植(3)----U-boot stage2分析
  2. php 中php-fpm 的重启、终止操作命令
  3. JavaScript语言基础-作用域
  4. C#读写EXCEL(二) ZedGraph在Asp.net中的应用
  5. PHP中file_exists()判断中文文件名无效的解决方法
  6. tmux颜色高亮跟vim不一致的情况
  7. ZOJ3954 Seven-Segment Display
  8. FastDFS和apache/nginx整合
  9. selenium2 断言失败自动截图 (四)
  10. 关于ptrdiff_t