2 条题解
-
1
#include<iostream> #include<stack> #define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define int long long using namespace std; int n,h[50005],v[50005],s[50005],maxx=-1; stack<int> st; signed main(){ IO; cin>>n; for(int i=1;i<=n;i++){ cin>>h[i]>>v[i]; //左边 while(!st.empty()&&h[st.top()]<=h[i]) st.pop(); if(!st.empty()) s[st.top()]+=v[i]; st.push(i); }while(!st.empty()) st.pop();for(int i=n;i>=1;i--){ //右边 while(!st.empty()&&h[st.top()]<=h[i]) st.pop(); if(!st.empty()) s[st.top()]+=v[i]; st.push(i); }for(int i=1;i<=n;i++) maxx=max(maxx,s[i]); cout<<maxx; return 0; }
信息
- ID
- 2498
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 21
- 已通过
- 8
- 上传者