1760D: Challenging Valleys ⧉
If the curve has more than two local minima, then it must also have a local maximum, and hence it contains a peak. Valleys only, around here.
_72#if NOT_LINUX_72#include "macos_includes.h"_72#else_72#include <bits/stdc++.h>_72#endif_72_72#if LOCAL_72#include "debug.h"_72#include "gxlib.h"_72#else_72#define dbg(...) 'x'_72#endif_72_72using namespace std;_72using ll = long long;_72const char nl = '\n';_72const int MAX_INT = std::numeric_limits<int>::max();_72const ll MAX_LL = std::numeric_limits<ll>::max();_72_72void solve() {_72 int n;_72 cin >> n;_72 vector<ll> a(n), adjR(n), adjL(n);_72 for (auto& i : a) {_72 cin >> i;_72 }_72_72 a.erase(unique(a.begin(), a.end()), a.end());_72_72 int minima = 0;_72_72 int m = a.size();_72_72 for (int i = 0; i < m; ++i) {_72 if (i == 0) {_72 if (a[i] < a[i+1])_72 minima++;_72_72 continue;_72 } else if (i == m-1) {_72 if (a[i] < a[i-1])_72 minima++;_72_72 continue;_72 }_72_72 if (a[i-1] > a[i] && a[i] < a[i+1])_72 minima++;_72_72 if (minima >= 2) break;_72 }_72_72 if (minima < 2) {_72 cout << "YES\n";_72 } else {_72 cout << "NO\n";_72 }_72}_72_72_72int main() {_72 ios::sync_with_stdio(false);_72 cin.tie(nullptr);_72_72 int t;_72 cin >> t;_72 for (int tc = 1; tc <= t; ++tc) {_72 //cout << "Case " << tc << ":\n";_72 solve();_72 }_72 return 0;_72}
If you found this solution helpful, consider leaving a star!