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 ;
}

Hard Rock的更多相关文章

  1. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  2. POJ - 2339 Rock, Scissors, Paper

    初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法. 后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做 ...

  3. ROCK 聚类算法‏

    ROCK (RObust Clustering using linKs)  聚类算法‏是一种鲁棒的用于分类属性的聚类算法.该算法属于凝聚型的层次聚类算法.之所以鲁棒是因为在确认两对象(样本点/簇)之间 ...

  4. Rice Rock

    先翻译评分要点,然后一点点翻译程序实现过程 如何产生一堆岩石? rock_group = set([])#空集合,全局变量   rock_group.add(a_rock) 要画出来draw hand ...

  5. HDOJ(HDU) 2164 Rock, Paper, or Scissors?

    Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...

  6. The Rock Game

    Before the cows head home for rest and recreation, Farmer John wantsthem to get some intellectual st ...

  7. 弹指之间 -- Folk Rock

    CHAPTER 17 民谣摇滚 Folk Rock 以8Beat为主,120左右的速度最能表现此节奏特色. 示例曲目: 略

  8. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  9. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

随机推荐

  1. char.IsLetter的使用

    先看一下下面的代码,大家会觉得控制台输出什么? 输出:Chiantxt  .对吗? 因为你看到char.IsLetter这个方法的文字的注释是这样写的: 但实际上输出的结果是这样的: ??? 怎么还输 ...

  2. Luogu3516 POI2011 Shift 构造

    传送门 题意:给出一个长为$N$的排列,有两种操作:$A$:将最后一个数字放到第一个:$B$:将第三个数字放到第一个.一次性使用某种操作$k$次写作$kA$或$kB$,其中在$kA$中$k < ...

  3. PMS-授权中心

    概述 授权中心用基于角色的访问控制思想(RBAC-Role Based Access Control)来实现各个业务系统的功能权限及数据权限控制.功能权限是指能否进入页面及使用页面上的操作.数据权限控 ...

  4. 微信小程序 canvas 绘图问题总结

    业务中碰到微信小程序需要生成海报进行朋友圈分享,这个是非常常见的功能,没想到实际操作的时候花了整整一天一夜才搞好,微信的 canvas 绘图实在是太难用了,官方快点优化一下吧. 业务非常简单,只需要将 ...

  5. JAVA核心:内存、比较和Final

    1.java是如何管理内存的 java的内存管理就是对象的分配和释放问题.(其中包括两部分) 分配:内存的分配是由程序完成的,程序员需要通过关键字new为每个对象申请内存空间(基本类型除外),所有的对 ...

  6. StoryLine3变量存储与跳转后台时的使用

    前言 公司项目原因,接触到storyline3(后面简称SL)课件制作工具,类似ppt,但是又多了互动.交互,且页面元素可添加触发器,触发器中可执行js代码. 1.官方教程 在SL中,会有“了解详情. ...

  7. 团队作业 week 14

    0. 在吹牛之前,先回答这个问题: 如果你的团队来了一个新队员,有一台全新的机器, 你们是否有一个文档,只要设置了相应的权限,她就可以根据文档,从头开始搭建环境,并成功地把最新.最稳定版本的软件编译出 ...

  8. Linux内核分析第三章读书笔记

    第三章 进程管理 3.1 进程 进程就是处于执行期的程序 进程就是正在执行的程序代码的实时结果 线程:在进程中活动的对象.每个线程都拥有一个独立的程序计数器.进程栈和一组进程寄存器. 内核调度的对象是 ...

  9. JS 柯里化 (curry)

    用 JS 理解柯里化 函数式编程风格,试图以函数作为参数传递(回调)和无副作用的返回函数(修改程序的状态). 很多语言采用了这种编程风格.JavaScript,Haskell,Clojure,Erla ...

  10. WinForm(WPF) splash screen demo with C#

    https://www.codeproject.com/Articles/21062/Splash-Screen-Control https://www.codeproject.com/Article ...