Educational Codeforces Round 148 (Rated for Div. 2) 1832C - Contrast Value Solution
Problem Link : https://codeforces.com/problemset/problem/1832/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- std::vector<int> a(n);
- long long sum = 0;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- if (i > 0) {
- sum += abs(a[i] - a[i - 1]);
- }
- }
- if (sum == 0) {
- cout << "1\n";
- } else {
- int ans = 2;
- n = unique(a.begin(), a.end()) - a.begin();
- for (int i = 1; i < n - 1; i++) {
- if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
- (a[i - 1] > a[i] && a[i + 1] > a[i]))
- ans++;
- }
- cout << ans << "\n";
- }
- }
- return 0;
- }
No comments