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. 模拟赛1030d1

    [问题描述]从1− ?中找一些数乘起来使得答案是一个完全平方数,求这个完全平方数最大可能是多少.[输入格式]第一行一个数字?.[输出格式]一行一个整数代表答案对100000007取模之后的答案.[样例 ...

  2. Web 项目下载图片简单处理方式

    1.如果图片头信息有 "Content-Disposition", "attachment; filename="fileName" 那么直接使用 i ...

  3. IOS开发之实现App消息推送

    转自:http://blog.csdn.net/shenjie12345678/article/details/41120637 第一部分 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps: ...

  4. 2.1顺序容器-vector

    vector 1) *   :使用vector必须包含vector头文件.可变长的动态数组,支持随机访问,所有STL算法都可以对vector进行操作. ** :随机根据下标访问某个元素的时间是一个常数 ...

  5. Java -- 访问控制

    原文:http://www.cnblogs.com/diyingyun/archive/2011/12/21/2295947.html 可见/访问性 在同一类中 同一包中 不同包中  同一包子类中  ...

  6. jQuery - 5.样式操作

    样式操作 1.获取样式 attr("class"), 2.设置样式attr("class","myclass"), 3.追加样式addCla ...

  7. GPT vs MBR 分区 ,,, Legacy BIOS vs UEFI BIOS

    MBR与GPT两种磁盘分区格式的区别 http://itoedr.blog.163.com/blog/static/120284297201378114053240 GPT Partition Tab ...

  8. K-MEANS算法总结

    K-MEANS算法 摘要:在数据挖掘中,K-Means算法是一种 cluster analysis 的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. 在数据挖掘中,K-M ...

  9. android 入门-android Studio git 克隆

    最后是完成 以上是如何从android studio Git 克隆Github的项目

  10. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statemen

    转自:http://www.cnblogs.com/iosdev/archive/2013/07/15/3190431.html mysql 配置文件目录:/etc/my.cnf root 密码为空的 ...