0
点赞
收藏
分享

微信扫一扫

小A的第一份工作

孟佳 2022-04-22 阅读 91
c++
#include<bits/stdc++.h>
using namespace std;
#define PLL pair<long long,long long>
#define fi first
#define se second

int main()
{
	int t;
	scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        stack<PLL> s;
        long long res1=0;
        for(int i=1;i<=n;i++)
        {
            long long x;
            scanf("%lld",&x);
            if(s.empty()||s.top().fi<=x) s.push({x,1});
            else
            {
                long long cnt=0;
                while(s.size()&&s.top().fi>x)
                {
                    PLL nw=s.top();
                    cnt+=nw.se;
                    s.pop();
                    if(res1<=nw.fi*cnt) res1=nw.fi*cnt;
                }
                s.push({x,cnt+1});//一定要加+1!!!!
            }
        }
        long long cnt=0;
        while(s.size())
        {
            PLL nw=s.top();
            cnt+=nw.se;
            s.pop();
           if(res1<=nw.fi*cnt) res1=nw.fi*cnt;
        }
        printf("%lld\n",res1);
    }
    return 0 - 0;
}
举报

相关推荐

0 条评论