UVa 11078 Open Credit System
本题可以边读边计算,MaxAi用来维护已经读入的数据的最大值,然后每次读入一个num,就计算一次MaxAi-num,如果比ans更大,就更新ans。
1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 7 int main(void) 8 { 9 #ifdef LOCAL 10 freopen("11078in.txt", "r", stdin); 11 #endif 12 13 int T; 14 scanf("%d", &T); 15 while(T--) 16 { 17 int n, MaxAi, ans = -999999, num, i; 18 scanf("%d", &n); 19 scanf("%d", &num); 20 MaxAi = num; 21 for(i = 2; i <= n; ++i) 22 { 23 scanf("%d", &num); 24 ans = max(ans, MaxAi - num); 25 MaxAi = max(MaxAi, num); 26 } 27 printf("%d\n", ans); 28 } 29 return 0; 30 }