Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome music video ever for their new single. In that music video Ilya will go through Manhattan standing on the top of a huge truck and playing amazing guitar solos. And during this show residents of the island will join in singing and shaking their heads. However, there is a problem. People on some streets hate rock.
Recall that Manhattan consists of n vertical and m horizontal streets which form the grid of ( n − 1)×( m − 1) squares. Band’s producer conducted a research and realized two things. First, band’s popularity is constant on each street. Second, a popularity can be denoted as an integer from 1 to 10 9. For example, if rockers go along the street with popularity equal to 10 9 then people will greet them with a hail of applause, fireworks, laser show and boxes with... let it be an orange juice. On the other hand, if rockers go along the street with popularity equal to 1 then people will throw rotten tomatoes and eggs to the musicians. And this will not help to make the most awesome music video!
So, a route goes from the upper left corner to the bottom right corner. Let us define the route coolness as the minimal popularity over all streets in which rockers passed non-zero distance. As you have probably guessed, the musicians want to find the route with the maximal coolness. If you help them then Ilya will even give you his autograph!

Input

In the first line there are integers n and m (2 ≤ nm ≤ 10 5), separated by space. These are the numbers of vertical and horizontal streets, respectively.
In the following n lines there are popularity values (one value on each line) on vertical streets in the order from left to right.
In the following m lines there are popularity values (one value on each line) on horizontal streets in the order from top to bottom.
It is guaranteed that all popularity values are integers from 1 to 10 9.

Output

Output a single integer which is a maximal possible route coolness.

Example

input output
2 3
4
8
2
7
3
4
4 3
12
4
12
3
21
5
16
12

解题思路:

题意:求从左上角刀右下角所经过街道的最小的权值,直接分成4种情况:不好描述,直接看代码:

#include<bits/stdc++.h>
using namespace std; int main()
{
int m,n,i,a[],b[];
cin>>m>>n;
int maxn = -,maxm = -;
for(i=;i<m;i++){
cin>>a[i];
if(a[i]>maxn&&i!=m-&&i!=)
maxn = a[i];
}
for(i=;i<n;i++){
cin>>b[i];
if(b[i]>maxm&&i!=n-&&i!=) maxm = b[i];
}
int min1 = min(b[],a[m-]);
int min2 = min(a[],b[n-]);
int min3 = min(a[],min(maxm,a[m-]));
int min4 = min(b[],min(maxn,b[n-]));
//cout<<min1<<min2<<min3<<min4<<endl;
int ans = max(max(min1,min2),max(min3,min4));
cout<<ans<<endl;
return ;
}

最新文章

  1. JavaScript 秘密花园 学习心得
  2. failover机制的小讨论
  3. python Function
  4. 一款新的PYTHON数据科学利器:yhat
  5. wordpress的创建
  6. 转 How to install XenServer Tools – Linux(forward)
  7. Path,Files巩固,题目:从键盘接收两个文件夹路径,把其中一个文件夹中(包含内容)拷贝到另一个文件夹中
  8. 转载: C++ 转换构造函数 和 类型转换函数
  9. andirod
  10. html5 app开发重大消息-腾讯在技术端推进Html5生态发展
  11. wxPython + Boa 练习程序
  12. php练习1
  13. 201521123093 java 第七周学习总结
  14. 详解散列hashCode在HashMap中的使用原理
  15. TP框架下载功能
  16. Python——Microsoft Office编程
  17. 解决python代码中含有中文报错
  18. Hadoop生态系统介绍
  19. Python序列之字符串 (str)
  20. docker-compsoe &amp; .netcore &amp; nginx

热门文章

  1. 源码分享篇:使用Python进行QQ批量登录
  2. c#对联合体的封装
  3. Log4j2使用笔记
  4. 清除EasyUi combotree下拉树的值
  5. Ubuntu 打包后安装提示:子进程 已安装 pre-removal 脚本 返回了错误号 1
  6. python中和生成器协程相关yield from之最详最强解释,一看就懂(二)
  7. java基础(个人学习笔记) A
  8. .NET持续集成与自动化部署之路第三篇——测试环境到生产环境的一键部署策略(Windows)
  9. JVM规范系列第2章:Java虚拟机结构
  10. element-ui + vue + node.js 与 服务器 Python 应用的跨域问题