题解 | #Distance#
Distance
https://ac.nowcoder.com/acm/problem/14268
思路
代码
#include<bits/stdc++.h>
#define int long long
#define ull signed long long
using namespace std;
const int N=1e5+7;
const int mod=1e9+7;
int n,a[N],b[N],c[N];
ull ansb,ansc;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=i*i+a[i]*a[i];
c[i]=i*i-a[i]*a[i];
}
sort(b+1,b+1+n);
sort(c+1,c+1+n);
ansb=(ull)max(abs(b[n]-b[1]),abs(b[1]-b[n]));
ansc=(ull)max(abs(c[n]-c[1]),abs(c[1]-c[n]));
cout<<(ull)max(ansb,ansc)<<"\n";
return 0;
}