题目链接:https://atcoder.jp/contests/abc178/tasks/abc178_e
题意:给定n组坐标 求
思路: 去绝对值化简 假设xi>xj
有xi-xj+yi-yj 则(xi+yi)-(xj+yj)
或者有 xi-xj-yi+yj 则 (xi-yi)-(xj-yj) 所以把用两个数组记录x+y x-y 排序在找最大的差即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define pb push_back 5 const int maxn =2e5+10; 6 const int mod=1e9+7; 7 8 9 10 11 int main() 12 { 13 ios::sync_with_stdio(false); 14 cin.tie(0); 15 int n; 16 cin>>n; 17 vector<int>a,b; 18 for(int i=1;i<=n;i++) 19 { 20 int x,y; 21 cin>>x>>y; 22 int t=x+y; 23 int t2=x-y; 24 a.pb(t); 25 b.pb(t2); 26 } 27 sort(a.begin(),a.end()); 28 sort(b.begin(),b.end()); 29 cout<<max(a.back()-a.front(),b.back()-b.front())<<'\n'; 30 31 32 33 34 35 36 37 }View Code