#include "locmin.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <utility>
using ll = long long;

const int MAX_N = 500;
const int MAX_M = 500;
const ll INF = 2e18;
int n, m;
ll a[MAX_N + 1][MAX_M + 1];

ll get(int l, int c) {
    if(l <= 0 || c <= 0 || l > n || c > m) {
        return INF;
    } else if(a[l][c] == 0) {
        return a[l][c] = value(l, c);
    } else {
        return a[l][c];
    }
}

std::pair<int, int> find_locmin_point(int _n, int _m) {
    srand(time(0));
    n = _n;
    m = _m;
    while(true) {
        int l = rand() % n + 1;
        int c = rand() % m + 1;
        if(get(l - 1, c) > get(l, c) &&
           get(l + 1, c) > get(l, c) &&
           get(l, c - 1) > get(l, c) &&
           get(l, c + 1) > get(l, c)) {
            return {l, c};
        }
    }
}
