fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n;
  17. cin >> n;
  18.  
  19. vector<int> vec(n);
  20.  
  21. for(int i = 0; i < n; i++){
  22. cin >> vec[i];
  23. }
  24.  
  25. int ans = 0;
  26.  
  27. for(int i = 0; i < n - 1; i++){
  28. ans = max(ans , vec[n-1] - vec[i]);
  29. }
  30.  
  31. for(int i = 1; i < n; i++){
  32. ans = max(ans , vec[i] - vec[0]);
  33. }
  34.  
  35. for(int i = 0; i < n-1; i++){
  36. ans = max(ans , vec[i] - vec[i+1]);
  37. }
  38.  
  39. cout << ans << '\n';
  40. }
  41.  
  42.  
  43. signed main(){
  44. FastIO();
  45.  
  46. int t = 1;
  47. cin >> t;
  48.  
  49. while (t--){
  50. solve();
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
6
1 3 9 11 5 7
1
20
3
9 99 999
4
2 1 8 1
3
2 1 5
stdout
10
0
990
7
4