kot_mapku3

2 G

Jun 2nd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     ios::sync_with_stdio(false);
  11.     cin.tie(nullptr);
  12.     cout.tie(nullptr);
  13.  
  14.     long long n; cin >> n;
  15.     vector<long long> v(n);
  16.     vector<long long> lmin, lmax;
  17.     long long imax = 0, imin = 0;
  18.  
  19.     for (long long i = 0; i < n; ++i) {
  20.         cin >> v[i];
  21.         if (v[imin] > v[i]) imin = i;
  22.         if (v[imax] < v[i]) imax = i;
  23.     }
  24.  
  25.     if (v.size() == 1) {cout << "1 1\n1 1\n1 1"; return 0;}
  26.     if (v.size() == 2) {}
  27.     if (v[0] > v[1]) lmax.push_back(1);
  28.     if (v[0] < v[1]) lmin.push_back(1);
  29.     for (long long j = 1; j < n-1; ++j) {
  30.         if (v[j] < v[j-1] && v[j] < v[j+1]) lmin.push_back(j+1);
  31.         if (v[j] > v[j-1] && v[j] > v[j+1]) lmax.push_back(j+1);
  32.     }
  33.     if (v[n-1] > v[n-2]) lmax.push_back(n);
  34.     if (v[n-1] < v[n-2]) lmin.push_back(n);
  35.  
  36.     cout << lmin.size() << " ";
  37.     for(long long x: lmin) cout << x << " "; cout << "\n";
  38.     cout << lmax.size() << " ";
  39.     for(long long x: lmax) cout << x << " "; cout << "\n";
  40.     cout << imin + 1 << " " << imax + 1;
  41.  
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment