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. java获取短uuid

    public static String[] chars = new String[] { "a", "b", "c", "d&q ...

  2. 一个TextView内显示不同颜色的文字

    String format = "<font color='#FC8262'>%s</font>:%s"; String text = String.for ...

  3. Cocoapods的使用教程

    前言 对于iOS App的开发,几乎都采用了Cocoapods来管理第三方库,那么对于我们开发人员来说,这是必备技能,必须要掌握如何使用.这篇文章就是介绍如何安装和使用CocoaPods的. 这篇文章 ...

  4. mysql 三个表连接查询

    权限表(permission)10 字段名称 类型 约束 描述 authorityid integer Pk not null 权限流水号id    PK userNameId int not nul ...

  5. C#实现http协议下的多线程文件传输

    用C#实现HTTP协议下的多线程文件传输转自  http://developer.51cto.com/art/201105/263066_all.htm C#(C Sharp)是微软(Microsof ...

  6. Android4.4 以太网和DHCP启动过程介绍

    转自:http://blog.csdn.net/wlwl0071986/article/details/51451843 Android4.4已经加入了以太网的支持.现在对以太网的初始化流程.网络策略 ...

  7. php支付宝接口用法

    现在流行的网站支持平台,支付宝当仁不让的老大了,现在我们就来告诉你如何使用支付宝api来做第三方支付,把支付宝放到自己网站来, alipay_config.php配置程序如下: <?php */ ...

  8. Gmail 账号找回办法

    前段时间一直在用GFW代理,结果发现GOOGLE账户的保护机制起用了,要给以前的手机号发消息,结果哪个号现在不用了,所以就登陆不进去了,非常扯淡,索性谷歌了下,得出如下的解决方案,完美解决,下次直接在 ...

  9. Delphi测试线程的时间

    在16位时代,当我们在Windows3.x下编程时,经常会用到GetTickCount()或者timeGetTime()来判断一段代码的执行时间.示例如下 var StartTime, Total: ...

  10. JavaScript之作用域与闭包详解

    前言: JavaScript是一种应用非常广泛的语言,其也有一些自身特点和优势,本文重在讲述其作用域机制以及闭包,会从一些实例来探讨其机理. 作用域在JavaScript程序员日常使用中有不同的含义, ...