洛谷 P5146 最大差值
题目传送门
好水的题...
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 int n,m = 999999999,a,ans = -999999; 7 8 inline int max(int s,int d) { 9 if(s >= d) return s; 10 else return d; 11 } 12 13 int main() { 14 scanf("%d",&n); 15 for(int i = 1;i <= n; i++) { 16 scanf("%d",&a); 17 if(a < m) m = a; 18 else ans = max(ans,a - m); 19 } 20 printf("%d",ans); 21 return 0; 22 }