#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
bool rowcom(pair<int, int> a, pair<int, int> b){
return a.first < b.first;
}
bool colcom(pair<int, int> a, pair<int, int> b){
return a.second < b.second;
}
int main()
{
int n , t;
cin >> n;
cin >> t;
vector<pair<int, int>> a(t+2);
vector<pair<int, int>> b(t+2);
a[0] = {0, 0};
b[0] = {0, 0};
for(int i = 1; i <= t; i++){
cin >> a[i].first;
cin >> a[i].second;
b[i].first = a[i].first;
b[i].second = a[i].second;
}
a[t+1] ={n+1, n+1};
b[t+1] ={n+1, n+1};
sort(a.begin(), a.end(), rowcom);
sort(b.begin(), b.end(), colcom);
int result = 0;
for(int k = 0; k <= t; k++){
pair<int, int> l = a[k];
for(int i = k+1; i <= t+1; i++){
pair<int, int> r = a[i];
int ma = 0;
int pre = 0;
int d = r.first - l.first - 1;
for(int j = 1; j <= t; j++){
pair<int, int> tt = b[j];
if(tt.first < r.first && tt.first > l.first){
ma = max(ma, tt.second- pre - 1);
pre = tt.second;
}
}
ma = max(ma, n + 1 - pre - 1);
result = max(result, min(d, ma));
}
}
cout<<result<<endl;
}
top of page
Recent Posts
See All#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...
s1 = input() s2 = input() silly = '' silly_o = '' quiete = '-' i = 0 j = 0 while i < len(s1) and j < len(s2): if s1[i] != s2[j]: if...
#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; char...
bottom of page
Comments