#include "locmin.h"
#include <bits/stdc++.h>
using namespace std;

const long long maxn=505;

pair<int,int> find_locmin_point(int n, int m) {
    int l=1, r=m;

    while (l<=r) {
        int mid=(l+r)/2;

        int best_row = 1;
        for(int i=2;i<=n;i++) {
            if(value(i,mid)<value(best_row,mid)) {
                best_row=i;
            }
        }

        long long cur =value(best_row, mid);
        long long left = (mid>1 ? value(best_row, mid - 1) : LLONG_MAX);
        long long right = (mid < m ? value(best_row, mid + 1) : LLONG_MAX);

        if (cur < left && cur < right) {
            return {best_row, mid};
        }
        else if (left < cur) {
            r= mid - 1;
        }
        else {
            l= mid + 1;
        }
    }

    return {1,1};
}
