给一个长度为n的序列,然后我们找一对数使得Ai-Aj的值最大并且i
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(){int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);int ans=-2147483647,maxn=-214748364,tmp;
for(register int i=1;i<=n;i++){scanf("%d",&tmp);ans=max(ans,maxn-tmp);maxn=max(maxn,tmp);}
printf("%d\n",ans);
}
return 0;
}
本文介绍了一种算法,用于在一个整数序列中找到两个元素,使得两元素之差绝对值最大。通过一次遍历实现了高效求解。

711

被折叠的 条评论
为什么被折叠?



