双指针解法
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000+5;
int a[N];int main() {ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);int n;while(cin >> n) {int ans = 0;if(n == 1) {cout << 0 << endl;continue;}for(int i = 0; i < n; i++) cin >> a[i];for(int i = 0, j = 1; j < n; j++) {if(a[j] - a[j-1] < 0) i = j;ans = max(ans, a[j] - a[i]);}cout << ans << endl;}return 0;
}