码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1657 奶牛的歌声

时间:2016-12-06 11:22:50      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:while   bsp   string   amp   stream   class   单调栈   using   algo   

单调栈。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50050
using namespace std;
int n,v[maxn],h[maxn],s[maxn],ans[maxn],t=0;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d%d",&h[i],&v[i]);
    for (int i=1;i<=n;i++)
    {
        while (t && h[i]>h[s[t]]) ans[i]+=v[s[t--]];
        s[++t]=i;
    }
    t=0;
    for (int i=n;i>=1;i--)
    {
        while (t && h[i]>h[s[t]]) ans[i]+=v[s[t--]];
        s[++t]=i;
    }
    int mx=0;
    for (int i=1;i<=n;i++) mx=max(mx,ans[i]);
    printf("%d\n",mx);
    return 0;
}

 

BZOJ 1657 奶牛的歌声

标签:while   bsp   string   amp   stream   class   单调栈   using   algo   

原文地址:http://www.cnblogs.com/ziliuziliu/p/6136853.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!