题意:
给一个序列,找两个整数a[i],a[j]使得a[i]-a[j]最大;
思路:
从前往后扫一遍;水题;
AC代码:
#include <bits/stdc++.h> /* #include <vector> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> */ using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define Riep(n) for(int i=1;i<=n;i++) #define Riop(n) for(int i=0;i<n;i++) #define Rjep(n) for(int j=1;j<=n;j++) #define Rjop(n) for(int j=0;j<n;j++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar(' '); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e18; const int N=1e5+10; const int maxn=1005; const double eps=1e-10; int n; int a[N]; int main() { int t; read(t); while(t--) { read(n); For(i,1,n)read(a[i]); int mmax=a[1],ans=-11000000; For(i,2,n) { ans=max(ans,mmax-a[i]); if(a[i]>mmax)mmax=a[i]; } cout<<ans<<" "; } return 0; }