Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cmath>
- #include <vector>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- long long n; cin >> n;
- vector<long long> v(n);
- vector<long long> lmin, lmax;
- long long imax = 0, imin = 0;
- for (long long i = 0; i < n; ++i) {
- cin >> v[i];
- if (v[imin] > v[i]) imin = i;
- if (v[imax] < v[i]) imax = i;
- }
- if (v.size() == 1) {cout << "1 1\n1 1\n1 1"; return 0;}
- if (v.size() == 2) {}
- if (v[0] > v[1]) lmax.push_back(1);
- if (v[0] < v[1]) lmin.push_back(1);
- for (long long j = 1; j < n-1; ++j) {
- if (v[j] < v[j-1] && v[j] < v[j+1]) lmin.push_back(j+1);
- if (v[j] > v[j-1] && v[j] > v[j+1]) lmax.push_back(j+1);
- }
- if (v[n-1] > v[n-2]) lmax.push_back(n);
- if (v[n-1] < v[n-2]) lmin.push_back(n);
- cout << lmin.size() << " ";
- for(long long x: lmin) cout << x << " "; cout << "\n";
- cout << lmax.size() << " ";
- for(long long x: lmax) cout << x << " "; cout << "\n";
- cout << imin + 1 << " " << imax + 1;
- return 0;
- }
Add Comment
Please, Sign In to add comment