#include "locmin.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<vector<bool>> explored;

std::pair <int, int> find_locmin_point(int height, int width)
{
    bool found = false;
    explored.assign(height, vector<bool>(width, false));
    ll i = 0, j = 0, cur;
    ll val = value(i+1, j+1);
    while(true)
    {
        found = false;
        for(ll it = 1; it <= 4 && !found; it++)
        {
            ll ni = it == 1 ? i+1 : it == 3 ? i-1 : i;
            ll nj = it == 2 ? j+1 : it == 4 ? j-1 : j;
            if(ni < 0 || ni >= height || nj < 0 || nj >= width) continue;
            cur = value(ni+1, nj+1);
            if(cur < val)
            {
                found = true;
                i = ni;
                j = nj;
                val = cur;
            }
        }
        if(!found)
        {
            return {i+1, j+1};
        }
    }
}
