#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e2 + 10;
const int INF = 2e9;
int n, r, c;
pair<int, int> p[MAXN];
vector<int> h;
void input() {
cin >> r >> c >> n;
for (int i = 0; i < n; i++)
cin >> p[i].second >> p[i].first;
sort(p, p + n);
}
int find(int x, int y) {
int l1 = 0, r1 = 0, s1 = 0;
for (int i = 1; i <= r; i++) {
h.clear();
for (int j = 0; j < n; j++) {
if ((p[j].second <= j && p[j].second + y >= j) || (p[j].second >= j && p[j].second - x <= j))
h.push_back(p[j].first);
}
if (h.empty())
return INF;
l1 = max(l1, h[0] - 1);
r1 = max(r1, c - h.back());
s1 = max({s1, l1, r1});
for (int i = 1; i < h.size(); i++)
s1 = max(s1, h[i] - h[i - 1] - 1);
}
return max(s1, l1 + r1);
}
int findAns() {
int res = INF;
for (int i = 0; i < r; i++)
for (int j = 0; j < r; j++)
res = min(res, find(i, j) + i + j);
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
input();
cout << findAns() << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |