P1901 发射站

点击查看代码
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N=1e6+10;
LL h[N],v[N],ans[N];
int n;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;

    for(int i=1;i<=n;i++){
        cin>>h[i]>>v[i];
    }

    stack<int> stk;

    for(int i=1;i<=n;i++){
        while(!stk.empty()&&h[i]>h[stk.top()]){
            int idx=stk.top();
            stk.pop();
            ans[i]+=v[idx];
        }

        if(!stk.empty()){
            int idx=stk.top();
            ans[idx]+=v[i];
        }

        stk.push(i);
        
    }

    LL mx=0;
    for(int i=1;i<=n;i++){
        mx=max(ans[i],mx);
    }

    cout<<mx<<endl;

    return 0;
}
posted @ 2026-02-05 20:46  AnoSky  阅读(2)  评论(0)    收藏  举报