2069. Hard Rock

Time limit: 1.0 second
Memory limit: 64 MB
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 109. For example, if rockers go along the street with popularity equal to 109 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 ≤ 105), 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 109.

Output

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

Samples

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

Notes

Explanation of the first sample (the "coolest" route is highlighted):
Problem Author: Oleg Merkurev (prepared by Alexander Borzunov)
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 159
 
题意:一个方格图,共有n+m条线,一个人从左上角走到右下角,问使路径上最小值最大。
分析:
这个人要么先横着走,走到某个点,然后下到最底部,然后再横着走到终点
要么先竖着走,走到某个点,然后横着走到最右部,然后再竖着走到终点
以上直觉是对的,但是我证明了下
 
证明:如果最优路径不是这样的
假设最优路径是先竖着走(跟先横着走是对称情况,同理可以证明先横着走的)
那么它一定要在某个点横着走的,
也就是说,前两步我们可以跟答案一样,
考虑到最优路径跟我们不一样,
如果最优路径的最后一步是竖着走的,那么我们的路径走过的边最优路径都走了,答案不可能比其劣
如果最优路径最后一步是横着走的,那么我们可以先竖着走到最下部,然后横着走,答案也不可能比其劣
也就说我们这样走的方法就是最优答案
 
 
 

ural 2069. Hard Rock的更多相关文章

  1. URAL 2069 Hard Rock (最短路)

    题意:给定 n + m 个街道,问你从左上角走到右下角的所有路的权值最小的中的最大的. 析:我们只要考虑几种情况就好了,先走行再走列和先走列再走行差不多.要么是先横着,再竖着,要么是先横再竖再横,要么 ...

  2. 【找规律】URAL - 2069 - Hard Rock

    题解及证明:http://www.cnblogs.com/StupidBoy/p/5241258.html #include<cstdio> #include<algorithm&g ...

  3. URAL 1936 Roshambo 题解

    http://acm.timus.ru/problem.aspx?space=1&num=1936 F - Roshambo Time Limit:1000MS Memory Limit:65 ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  9. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

随机推荐

  1. Oracle dbms_lock.sleep()存储过程使用技巧-场景-分析-实例

    <Oracle dbms_lock.sleep()存储过程使用技巧>-场景-分析-实例 摘要:今天是2014年3月10日,北京,雾霾,下午组织相关部门开会.会议的结尾一名开发工程师找到了我 ...

  2. NYOJ题目806HEIHEI的心情

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAANRCAIAAACumacBAAAgAElEQVR4nOzdrXLrOrjG8XMT5b2Q4l

  3. ThinkPHP入门(二)

    smarty使用 smarty引入流程 1. 控制器IndexAction.class.php function index() $this -> display(); (父类Action的di ...

  4. python 取两数的百分比

    Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...

  5. C#回顾 - 3.NET的IO:字节流

    使用 Stream 类管理字节流 使用 FileStream 类管理文件数据 使用 MemoryStream 类管理内存数据 使用 BufferedSream 类提高流性能   3.1 FileStr ...

  6. Redis笔记(七)Java实现Redis消息队列

    这里我使用Redis的发布.订阅功能实现简单的消息队列,基本的命令有publish.subscribe等. 在Jedis中,有对应的java方法,但是只能发布字符串消息.为了传输对象,需要将对象进行序 ...

  7. Spell checker

     Spell checker Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  8. .NET Framework 4 与 .NET Framework 4 Client Profile

    今天碰到的一个问题和Client Profile相关的.问题是这样的:一个WPF工程,需要引用另外几个.NET的assembly, 在WPF工程中添加了对这几个assembly的引用,并在程序中可以添 ...

  9. JqueryEasyUI 解决IE下datagrid无法刷新的问题 分类: JavaScript JqueryEasyUI 2014-09-20 10:05 510人阅读 评论(1) 收藏

    问题描述: 在使用JqueryEasyUI 时,发现在IE下$('#table').datagrid('reload');无效,数据并没有被刷新,究其原因,是因为刷新时,datagrid请求的url没 ...

  10. 第二十三篇:在SOUI中使用LUA脚本开发界面

    像写网页一样做客户端界面可能是很多客户端开发的理想. 做好一个可以实现和用户交互的动态网页应该包含两个部分:使用html做网页的布局,使用脚本如vbscript,javascript做用户交互的逻辑. ...