Advertisement
Korotkodul

2_B_v1

Oct 24th, 2023 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <stack>
  4. #include <vector>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::max;
  9. using std::min;
  10. using std::string;
  11. using std::vector;
  12. using std::stack;
  13. using ll = long long;
  14. using pll = std::pair <long long, long long>;
  15. //long long?
  16. int main() {
  17.   int n;
  18.   cin >> n;
  19.   vector<ll> arr(n);
  20.   for (ll& el: arr) {
  21.     cin >> el;
  22.   }
  23.   vector<int> rt(n);
  24.   vector<int> lt(n);
  25.   rt[n - 1] = n;
  26.   lt[0] = -1;
  27.   stack<pll> st;
  28.   st.push({arr[n - 1], n - 1});
  29.  
  30.   cout << "arr\n";
  31.   for (ll el: arr) {
  32.     cout << el << ' ';
  33.   } cout << "\n";
  34.  
  35.   cout << "make rt\n";
  36.   for (int i = n - 2; i >= 0; --i) {
  37.     cout << "i = " << i << "\n";
  38.     while (!st.empty() && arr[i] <= st.top().first) {
  39.       cout << "top\n";
  40.       cout << st.top().first << ' ' << st.top().second << "\n";
  41.       st.pop();
  42.     }
  43.     if (st.empty()) {
  44.       rt[i] = n;
  45.     } else {
  46.       rt[i] = st.top().second;
  47.     }
  48.     cout << "choice " << rt[i] << "\n";
  49.     st.push({arr[i], i});
  50.   }
  51.  
  52.   while (!st.empty()) {
  53.     st.pop();
  54.   }
  55.   st.push({arr[0], 0});
  56.   for (int i = 1; i < n; ++i) {
  57.     while (!st.empty() && arr[i] <= st.top().first) {
  58.       cout << "top\n";
  59.       cout << st.top().first << ' ' << st.top().second << "\n";
  60.       st.pop();
  61.     }
  62.     if (!st.empty()) {
  63.       lt[i] = st.top().second;
  64.     } else {
  65.       lt[i] = -1;
  66.     }
  67.     cout << "choice " << lt[i] << "\n";
  68.     st.push({arr[i], i});
  69.   }
  70.  
  71.   cout << "rt\n";
  72.   for (int el: rt) {
  73.     cout << el << ' ';
  74.   } cout << "\n";
  75.  
  76.   cout << "lt\n";
  77.   for (int el: lt) {
  78.     cout << el << ' ';
  79.   } cout << "\n";
  80.  
  81.   ll ans = -1;
  82.   for (int i = 0; i < n; ++i) {
  83.     ll now = (rt[i] - lt[i] - 1) * arr[i];
  84.     ans = max(ans, now);
  85.   }
  86.   cout << ans;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement