/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 4ms 436.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 2ms 440.0 KiB
#5 Accepted 1ms 308.0 KiB
#6 Accepted 13ms 956.0 KiB
#7 Accepted 12ms 952.0 KiB
#8 Accepted 16ms 952.0 KiB
#9 Accepted 17ms 960.0 KiB
#10 Accepted 16ms 956.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
int n,s[50002],d[50002],ans[50002],ANS,a[50002],b[50002],r,i;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
    s[1]=a[1];d[1]=1;r=1;
    for(i=2;i<=n;i++)
    {
        while(r!=0&&a[i]>s[r]){ans[i]+=b[d[r]];r--;}
        r++;
        s[r]=a[i];
        d[r]=i;
    }
    s[1]=a[n];d[1]=n;r=1;
    for(i=n-1;i>=1;i--)
    {
        while(r!=0&&a[i]>s[r]){ans[i]+=b[d[r]];r--;}
        r++;
        s[r]=a[i];
        d[r]=i;
    }
    for(i=1;i<=n;i++)ANS=max(ANS,ans[i]);
    cout<<ANS;
    return 0;
}

信息

递交者
类型
递交
题目
财富 T1
题目数据
下载
语言
C++
递交时间
2017-10-04 13:11:45
评测时间
2017-10-04 13:17:11
评测机
分数
100
总耗时
89ms
峰值内存
960.0 KiB