Submission #321770

#TimeUsernameProblemLanguageResultExecution timeMemory
321770alextodoran3D Histogram (COCI20_histogram)C++17
20 / 110
2576 ms5952 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200002; const int L_MAX = 1000002; int n; int a[N_MAX], b[N_MAX]; vector <pair <int, int> > vp; vector <int> st; int L[N_MAX], R[N_MAX]; int a1[N_MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for(int i = 1; i <= n; i++) vp.push_back(make_pair(b[i], i)); sort(vp.begin(), vp.end()); reverse(vp.begin(), vp.end()); a1[0] = a1[n + 1] = -1; ll ans = 0; for(pair <int, int> p : vp) { int x = p.second; a1[x] = a[x]; st.push_back(0); for(int i = 1; i <= n; i++) { while(a1[st.back()] >= a1[i]) st.pop_back(); L[i] = i - st.back() - 1; st.push_back(i); } st.clear(); st.push_back(n + 1); for(int i = n; i >= 1; i--) { while(a1[st.back()] >= a1[i]) st.pop_back(); R[i] = st.back() - i - 1; st.push_back(i); } st.clear(); for(int i = 1; i <= n; i++) ans = max(ans, 1LL * b[x] * a1[i] * (L[i] + R[i] + 1)); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...