D. Minimax Problem
time limit per test

5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given nn arrays a1a1, a2a2, ..., anan; each array consists of exactly mm integers. We denote the yy-th element of the xx-th array as ax,yax,y.

You have to choose two arrays aiai and ajaj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j). After that, you will obtain a new array bb consisting of mmintegers, such that for every k∈[1,m]k∈[1,m] bk=max(ai,k,aj,k)bk=max(ai,k,aj,k).

Your goal is to choose ii and jj so that the value of mink=1mbkmink=1mbk is maximum possible.

Input

The first line contains two integers nn and mm (1≤n≤3⋅1051≤n≤3⋅105, 1≤m≤81≤m≤8) — the number of arrays and the number of elements in each array, respectively.

Then nn lines follow, the xx-th line contains the array axax represented by mm integers ax,1ax,1, ax,2ax,2, ..., ax,max,m (0≤ax,y≤1090≤ax,y≤109).

Output

Print two integers ii and jj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j) — the indices of the two arrays you have to choose so that the value of mink=1mbkmink=1mbk is maximum possible. If there are multiple answers, print any of them.

Example
input

Copy
6 5
5 0 3 1 2
1 8 9 1 3
1 2 3 4 5
9 1 0 3 7
2 3 0 6 3
6 4 1 7 0
output

Copy
1 5
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#define met(a,x) memset(a,x,sizeof(a));
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define bep(i,a,b) for(ll i = a;i >= b;i--)
#define lowbit(x) (x&(-x))
// #define mid ((l + r) >> 1)
// #define len (r - l + 1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pb push_back
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b == ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
typedef unsigned long long ull;
typedef pair<int, int>Pi;
typedef pair<ll, pair<ll, ll> > Pii;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-);
const ll maxn = ;
const ll mod = ;
int a[maxn][];
int n, m,xx,yy;
int ok(int x) {
int vis[] = { };
rep(i,,n){
int now = ;
rep(j,,m){
if(a[i][j] >= x)now = now* + ;
else now = now*;
}
vis[now] = i;
}
rep(i, , ) {
rep(j, , ) {
if (vis[i] && vis[j] && ((i|j) == (( << m) - ))) {
xx = vis[i];
yy = vis[j];
return ;
}
}
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
rep(i, , n) {
rep(j, , m) {
scanf("%d",&a[i][j]);
}
}
int l = , r = 1e9;
while (l <= r) {
int mid = (l + r) / ;
if (ok(mid)) l = mid + ;
else r = mid - ;
}
cout << xx << ' ' << yy << endl;
return ;
}

D. Minimax Problem(二分+二进制)的更多相关文章

  1. 【codeforces】Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理

    题目链接 题目大意 有n个维度为m的向量,取其中两个进行合并,合并时每个维度取两者之间的较大者,得到的新的向量中,维度值最小者最大为多少 分析 首先最需要注意的是m的取值,m最大只有8 那么我们可以二 ...

  2. codeforces 1288D. Minimax Problem(二分)

    链接:https://codeforces.com/contest/1288/problem/D D. Minimax Problem 题意:给定n个数组,长度为m,从n中数组挑选两个数组,两个数组中 ...

  3. D. Minimax Problem Codeforces 1288D binary_search+二进制

    题目大意:n*m的矩阵中,找到两行数,可以形成两个一维数组,数组1的位置i和数组2的位置i去最大构成新数组b的元素b[i],最终目的要使数组b中最小的数尽可能的大 题解: m的范围是(1,8),比较小 ...

  4. HDU 4282 A very hard mathematic problem 二分

    A very hard mathematic problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sh ...

  5. atcoder ARC092 D - Two Sequences 二分 & 二进制

    今天生日捏,嘻嘻~ 题意:给定A B数组长度为n 求所有 (1<=i,j <=n ) a[i]+b[j] 的异或和. n <=200000  ai bi <=228 这题比赛没 ...

  6. POJ-2452 Sticks Problem 二分+RMQ

    题目链接: https://cn.vjudge.net/problem/POJ-2452 题目大意: 给出一个数组a,求最大的j-i满足 i<j && a[i] ... a[j] ...

  7. Manthan, Codefest 16 B. A Trivial Problem 二分 数学

    B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...

  8. D. Dasha and Very Difficult Problem 二分

    http://codeforces.com/contest/761/problem/D c[i] = b[i] - a[i],而且b[]和a[]都属于[L, R] 现在给出a[i]原数组和c[i]的相 ...

  9. Codeforces 1288D - Minimax Problem

    题目大意: 给定n个序列,每个序列元素个数严格相等于m 你需要找到两个序列a[i]和a[j],使其每个对应位置的元素取大后得到b序列  b[k]=max(a[i][k],a[j][k]) 且让b序列中 ...

随机推荐

  1. pop3&smtp

    pop3&smtp pop3 Post Office Protocol - Version 3 pop3协议是离线邮件协议,是客户端取邮件用的. 默认监听在TCP:110端口. POP3会话有 ...

  2. JS location.href传参及接受参数

    当前页面传参 window.location.href= + "&name="+"zhangchenxao"; 下个页面接受参数 var url = l ...

  3. 第十八篇 admin组件

    admin组件 admin组件使用 admin源码解析 admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以 ...

  4. Day 14:FileInputStream、FileOutputStream

    File类: 用于描述一个文件或者文件夹的. 通过File对象我们可以读取文件或者文件夹的属性数据,如果我们需要读取文件的内容数据,那么我们需要使用IO流技术. IO流(Input Output) I ...

  5. spring第9天(事务)

    依赖:spring-context,spring-jdbc(这个本身有依赖spring-tx,关于事务的),druid,mysql-connector-java,aspectjweaver五个 由于我 ...

  6. python outline

    1.列表/数组/numpy/Pandas Python list 初始化技巧   (2018-12-27 11:54) python3 sort list   (2019-05-23 14:52) P ...

  7. android 开发学习2

    Dao dao = new Dao(yi_ji_lu_zhang_dan.this);List<GetOneRecord> list = dao.getAllRecord();//创建迭代 ...

  8. 洛谷 P5542 [USACO19FEB]Painting The Barn

    题目传送门 解题思路: 二维差分的板子题.题解传送门 AC代码: #include<iostream> #include<cstdio> using namespace std ...

  9. ssi引用路径规则

    1.file:引用的是相对路径,相对当前文件的,特别注意使用file,被引用文件只能与当前文件同级.或下级.不能在其上级(不支持../) <!--#include file="head ...

  10. java课程课后作业190616之个人学期总结

    在团队开始的那一周,我们做了作品的功能畅想,在讲台上谈论了自己的产品可能会有的功能,比如说课程查找功能,空教室查找功能,霸屏功能,课程留言功能等,当然,随着开发的推进,我也发现了有些功能上实现的困难, ...