题目大意:给长度N的A1.....An 求(Ai-Aj)MAX
枚举n^2 其实动态维护最大值就好了
#include<iostream> #include<cstdio> using namespace std; int t,a[100005],n,ans,MAX; int main() { scanf("%d",&t); while (t--) { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); MAX=a[n];ans=-150000; for (int i=n-1;i>=1;i--) { ans=max(ans,a[i]-MAX); MAX=min(MAX,a[i]); } printf("%d ",ans); } }