2

Distance

http://www.nowcoder.com/questionTerminal/6295f81acd1b4fb59c8beed92577f64b

include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 100000 + 10;
const int INF = 1e9 + 7;
ll x[maxn], y[maxn];
int main()
{
int n, tmp;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &tmp), x[i] = (ll)i * i, y[i] = (ll)tmp * tmp;
ll ans = 0;
for(int i = 0; i < 4; i++)
{
ll Max = -1e18, Min = 1e18, tmp;
for(int j = 1; j <= n; j++)
{
if(i == 0)tmp = x[j] + y[j];
else if(i == 1)tmp = x[j] - y[j];
else if(i == 2)tmp = -x[j] + y[j];
else tmp = -x[j] - y[j];
Max = max(Max, tmp);
Min = min(Min, tmp);
}
ans = max(ans, Max - Min);
}
printf("%lld\n", ans);
return 0;
}

全部评论

相关推荐

我也曾抱有希望:说的好直白
点赞 评论 收藏
分享
喜欢吃蛋糕仰泳鲈鱼是我的神:字节可以找个hr 给你挂了,再放池子捞
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务