Advertisement
999ms

Untitled

Jan 23rd, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) (x).begin(),(x).end()
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. vector<int> Solve(vector<int>& arr) {
  8.     const int n = arr.size();
  9.     vector<int> l(n);
  10.     for (int i = 0; i < n; i++) {
  11.         l[i] = i;
  12.         while (l[i] > 0 && arr[l[i] - 1] >= arr[i]) {
  13.             l[i] = l[l[i] - 1];
  14.         }
  15.     }
  16.     return l;
  17. }
  18.  
  19. int main() {
  20.     const int n = 10;
  21.     vector<int> arr(n);
  22.     for (int i = 0; i < n; i++) {
  23.         arr[i] = rand() % 50;
  24.     }
  25.     auto l = Solve(arr);
  26.     reverse(all(arr));
  27.     auto r = Solve(arr);
  28.     reverse(all(r));
  29.     for (int i = 0; i < n; i++) {
  30.         r[i] = n - 1 - r[i];
  31.     }
  32.     ll ans = 0;
  33.     reverse(all(arr));
  34.     for (int i = 0; i < n; i++) {
  35.         ans = max(ans, 1ll * (r[i] - l[i] + 1) * arr[i]);
  36.     }
  37.     for (int i = 0; i < n; i++) {
  38.         cout << arr[i] << ' ' << l[i] << ' ' << r[i] << '\n';
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement