Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
2.4 kB
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

#define int long long
void __print(int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \
  cerr << "[" << #x << "] = [";                                                \
  _print(x)
#else
#define debug(x...)
#endif

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  // vector<int> b = a;
  // sort(b.begin(),b.end());
  // if(a[n-2]==b[n-2]){
  //   cout << b[n-2] << endl;
  // }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int flag_min2 = 0;
    int flag_min1 = 0;
    int flag_plus1 = 0;
    int flag_plus2 = 0;

    if (i - 2 >= 0) {
      flag_min2 = 1;
    }
    if (i - 1 >= 0) {
      flag_min1 = 1;
    }
    if (i + 1 < n) {
      flag_plus1 = 1;
    }
    if (i + 2 < n) {
      flag_plus2 = 1;
    }
    debug(flag_min1, flag_min2, flag_plus1, flag_plus2);

    int val_min1 = flag_min1 ? a[i - 1] : LLONG_MAX;
    int val_min2 = flag_min2 ? a[i - 2] : LLONG_MAX;
    int val_plus1 = flag_plus1 ? a[i + 1] : LLONG_MAX;
    int val_plus2 = flag_plus2 ? a[i + 2] : LLONG_MAX;
    if (a[i] <= val_min1 || a[i] <= val_min2 || a[i] <= val_plus1 ||
        a[i] <= val_plus2) {

      ans = max(ans, a[i]);
    }
  }
  // if(a[n-1]<=(a[n-2]) || a[n-1]<=(a[n-3])){
  //   ans = max(ans,a[n-1]);
  // }
  cout << ans << endl;
}

signed main() {
  int t = 1;
  cin >> t;
  while (t--) {
    debug(t);
    solve();
  }

  return 0;
}
Leave a Comment