Educational Codeforces Round 5 B. Dinner with Emma

来源:互联网 发布:java获取自己程序路径 编辑:程序博客网 时间:2024/04/30 08:06
B. Dinner with Emma
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.

Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from1 to n and the avenues are numbered with integers from1 to m. The cost of dinner in the restaurant at the intersection of thei-th street and the j-th avenue is cij.

Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan.

Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and thej-th avenue.

Output

Print the only integer a — the cost of the dinner for Jack and Emma.

Sample test(s)
Input
3 44 1 3 52 2 2 25 4 5 1
Output
2
Input
3 31 2 32 3 13 1 2
Output
1
Note

In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is2.

In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner1.


题意:两个人去吃饭,一个人要尽可能多花钱,一个人尽可能少花钱,一个决定行,一个决定列,然后确定一个餐厅


思路:直接取每行的最小值然后取最小值中的最大值


ac代码:

#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 1001000#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define mod 1000000007using namespace std;int main(){int i,n,m,j;ll a;while(scanf("%d%d",&n,&m)!=EOF){ll ma=-INF;for(i=0;i<n;i++){ll mi=INF;for(j=0;j<m;j++){scanf("%I64d",&a);mi=min(mi,a);}ma=max(ma,mi);}printf("%I64d\n",ma);}return 0;}


0 0
原创粉丝点击