1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <bits/stdc++.h> #define ll long long #define fupe(i,a,b) for(int i=a;i<=b;i++) #define fdowne(i,a,b) for(int i=a;i>=b;i--) #define fup(i,a,b) for(int i=a;i<b;i++) using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; vector<int> h(n),v(n),e(n); fup(i,0,n) cin>>h[i]>>v[i]; stack<int> st; fdowne(i,n-1,0) { while(!st.empty() && h[i]>=h[st.top()]){ st.pop(); } if(!st.empty()) { e[st.top()]+=v[i]; } st.push(i); } while(!st.empty()) st.pop(); fup(i,0,n) { while(!st.empty() && h[i]>=h[st.top()]) { st.pop(); } if(!st.empty()) { e[st.top()]+=v[i]; } st.push(i); } int ans = 0; fup(i,0,n) ans= max(ans,e[i]); cout<<ans; return 0; }
|