Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define maxm 1000001
- #define ll long long
- using namespace std;
- ll T, N, x, max_area, area;
- stack<ll> st;
- vector<ll> hist(maxm);
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin>>T;
- while(T--){
- cin>>N;
- max_area = 0;
- for(ll i=0; i<N; ++i)
- cin>>hist[i];
- for(ll i=0; i<N; ++i){
- if(st.empty() || hist[st.top()] <= hist[i])
- st.push(i);
- else{
- while(!st.empty() && hist[st.top()] > hist[i]){
- x = hist[st.top()];
- st.pop();
- area = st.empty() ? (x * i) : (x * (i-1-st.top()));
- max_area = max(max_area, area);
- }
- st.push(i);
- }
- }
- while(!st.empty()){
- x = hist[st.top()];
- st.pop();
- area = st.empty() ? (x * N) : (x * (N-1-st.top()));
- max_area = max(max_area, area);
- }
- cout<<max_area<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement