国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Ural 2069 Hard Rock

2019-11-08 03:16:30
字體:
來源:轉載
供稿:網友

Description

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≤n,m≤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.

題意

問有縱向 n 條路,橫向 m 條路,且彼此交叉,從左到右依次給出 n 條縱向路的權值,從上到下依次給出 m 條橫向路的權值,問如何從左上點經過若干條橫縱路到達右下點,使得進過道路的最小權值最大。

分析

此題重點在于思維,由于從左上到右下,則必然縱向 1 號路與 n 號路,橫向 1 號路與 m 號路均必有至少兩條被走到。

同時,可以想到,走到道路越少,則使得最終權值變小的可能越少。故組合情況共四種:

縱向 1 號路 - 橫向 m 號路縱向 1 號路 - 橫向 x 號路 - 縱向 n 號路橫向 1 號路 - 縱向 n 號路橫向 1 號路 - 縱向 y 號路 - 橫向 m 號路

此處要求的 x 為橫向路中除 1, m 路外權值最大的路,y 為縱向路中除 1, n 路外權值最大的路

代碼

#include<bits/stdc++.h>using namespace std;const int inf = 1e9 + 7;int col[100010], row[100010];int main(){ for(int n,m;scanf("%d %d",&n,&m)!=EOF;) { for(int i=1;i<=n;i++) scanf("%d",&col[i]); for(int j=1;j<=m;j++) scanf("%d",&row[j]); sort(col+2, col+n); sort(row+2, row+m); int ans = 0; int t1 = min(col[1], row[m]); int t2 = min(col[1], min(row[m-1], col[n])); int t3 = min(row[1], col[n]); int t4 = min(row[1], min(col[n-1], row[m])); ans = max(ans, t1); ans = max(ans, t2); ans = max(ans, t3); ans = max(ans, t4); printf("%d/n",ans); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙州县| 易门县| 凤凰县| 邻水| 哈密市| 延川县| 利津县| 丰都县| 房产| 隆回县| 杂多县| 新巴尔虎右旗| 东乌珠穆沁旗| 衡阳市| 金川县| 双峰县| 崇州市| 永济市| 库车县| 泗水县| 安新县| 竹溪县| 八宿县| 容城县| 庄河市| 东乌珠穆沁旗| 托克逊县| 屏山县| 晴隆县| 望都县| 阿拉尔市| 耿马| 桓仁| 台安县| 左贡县| 金寨县| 咸宁市| 喜德县| 大足县| 疏附县| 平罗县|