Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <stack>
- #include <vector>
- using std::cin;
- using std::cout;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- using std::stack;
- using ll = long long;
- using pll = std::pair <long long, long long>;
- //long long?
- int main() {
- int n;
- cin >> n;
- vector<ll> arr(n);
- for (ll& el: arr) {
- cin >> el;
- }
- vector<int> rt(n);
- vector<int> lt(n);
- rt[n - 1] = n;
- lt[0] = -1;
- stack<pll> st;
- st.push({arr[n - 1], n - 1});
- cout << "arr\n";
- for (ll el: arr) {
- cout << el << ' ';
- } cout << "\n";
- cout << "make rt\n";
- for (int i = n - 2; i >= 0; --i) {
- cout << "i = " << i << "\n";
- while (!st.empty() && arr[i] <= st.top().first) {
- cout << "top\n";
- cout << st.top().first << ' ' << st.top().second << "\n";
- st.pop();
- }
- if (st.empty()) {
- rt[i] = n;
- } else {
- rt[i] = st.top().second;
- }
- cout << "choice " << rt[i] << "\n";
- st.push({arr[i], i});
- }
- while (!st.empty()) {
- st.pop();
- }
- st.push({arr[0], 0});
- for (int i = 1; i < n; ++i) {
- while (!st.empty() && arr[i] <= st.top().first) {
- cout << "top\n";
- cout << st.top().first << ' ' << st.top().second << "\n";
- st.pop();
- }
- if (!st.empty()) {
- lt[i] = st.top().second;
- } else {
- lt[i] = -1;
- }
- cout << "choice " << lt[i] << "\n";
- st.push({arr[i], i});
- }
- cout << "rt\n";
- for (int el: rt) {
- cout << el << ' ';
- } cout << "\n";
- cout << "lt\n";
- for (int el: lt) {
- cout << el << ' ';
- } cout << "\n";
- ll ans = -1;
- for (int i = 0; i < n; ++i) {
- ll now = (rt[i] - lt[i] - 1) * arr[i];
- ans = max(ans, now);
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement