Perfect Ban

在《Wrath of Elves》这款游戏中,Constantine和Mike进行对决。每种种族和职业都有一个特定的角色,角色的战斗力已知。Mike可以禁用一个种族和一个职业,以使Constantine无法选择这两个。Mike的目标是让Constantine得到最弱的角色。输入包含所有角色的战斗力,输出Mike应该禁用的种族和职业编号,以使Constantine的战斗力最小。程序通过比较角色战斗力来找出最佳策略。

Constantine and Mike are playing the board game «Wrath of Elves». There are n races and m classes of characters in this game. Each character is described by his race and class. For each race and each class there is exactly one character of this race and this class. The power of the character of the i-th race and the j-th class equals to aij, and both players know it perfectly.

Now Constantine will choose a character for himself. Before that Mike can ban one race and one class so that Constantine would not be able to choose characters of this race or of this class. Of course, Mike does his best to leave Constantine the weakest possible character, while Constantine, on the contrary, chooses the strongest character. Which race and class Mike should ban?

Input
The first line contains two integers n and m (2 ≤ n, m ≤ 1000) separated by a space — the number of races and classes in the game «Wrath of Elves», correspondingly.

The next n lines contain m integers each, separated by a space. The j-th number in the i-th of these lines is aij (1 ≤ aij ≤ 109).

Output
In the only line output two integers separated by a space — the number of race and the number of class Mike should ban. Races and classes are numbered from one. If there are several possible answers, output any of them.

Examples
Input
2 2
1 2
3 4
Output
2 2
Input
3 4
1 3 5 7
9 11 2 4
6 8 10 12
Output
3 2

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000005;
struct node {
    int x, y, a;
} s[N];
int cmp(node a, node b) { return a.a > b.a; }
int main() {
    ios::sync_with_stdio(false);
    int n, m, i, j, k = 0, b, c;
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            cin >> c;
            s[k].x = i;
            s[k].y = j;
            s[k++].a = c;
        }
    }
    sort(s, s + k, cmp);
    int x = s[0].x;
    int y = -1;
    for (i = 1; i < k; i++) {
        if (y == -1) {
            if (s[i].x != x) {
                y = s[i].y;
                continue;
            }
        } else {
            if (s[i].x != x && s[i].y != y) {
                c = s[i].a;
                break;
            }
        }
    }
    int yy = s[0].y;
    int xx = -1;
    for (i = 1; i < k; i++) {
        if (xx == -1) {
            if (s[i].y != yy) {
                xx = s[i].x;
                continue;
            }
        } else {
            if (s[i].x != xx && s[i].y != yy) {
                b = s[i].a;
                break;
            }
        }
    }
    if (c < b)
        cout << x << ' ' << y << '\n';
    else
        cout << xx << ' ' << yy << '\n';
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值