# hdu 5699 货物运输 （啥）

http://acm.hdu.edu.cn/showproblem.php?pid=5699

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

#define eps 1e-9
#define LL long long
#define ULL unsigned long long
#define pii pair<int,int>
#define MP make_pair
#define N (2000000 + 10)
#define M (3000000 + 10)
#define inf 0x3f3f3f3f
#define ls i << 1
#define rs i<<1|1
#define lson ls, ll, md
#define rson rs, md+1, rr

int l[N], r[N];
int n, m;
bool check(int mid) {
int mi1 = inf, mi2 = inf, ma1 = -inf, ma2 = -inf;
bool e = 1;
for(int i = 0; i < m; ++i) {
if(r[i]-l[i] > mid) {
ma1 = max(ma1, r[i]-l[i] - mid);
mi1 = min(mi1, r[i]-l[i] + mid);
mi2 = min(mi2, l[i]+r[i] + mid);
ma2 = max(ma2, l[i]+r[i] - mid);
e = 0;
}
}
if(e) return 1;
if(mi1 == ma1 && mi2 == ma2) {
if((mi1 + mi2)&1) return 0;
}
return mi1 >= ma1 && mi2 >= ma2;
}

int main() {
while(~scanf("%d%d", &n ,&m)) {
for(int i = 0; i < m; ++i) {
scanf("%d%d", &l[i], &r[i]);
if(l[i] > r[i]) swap(l[i], r[i]);
}

int l = 0, r = n+1;
int ans = 0 ;
while(l < r) {
int mid = l+r>>1;
if(check(mid)) r = mid, ans = mid;
else l = mid+1;
}
printf("%d\n",ans);
}
}

05-31 538

05-23 936

10-16 57

05-22 1571

09-23 155

08-21 243

06-20 701

11-21 102

05-19 1419

03-19 98