P1901-发射站
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define _for(i,a,b) for(int i = (a);i < b;i ++) 4 #define _rep(i,a,b) for(int i = (a);i > b;i --) 5 #define INF 0x3f3f3f3f 6 #define pb push_back 7 #define maxn 1005390 8 typedef long long ll; 9 typedef pair<int,int> P;//first 是最短距离,second 是顶点编号 10 inline ll read() 11 { 12 ll ans = 0; 13 char ch = getchar(), last = ' '; 14 while(!isdigit(ch)) last = ch, ch = getchar(); 15 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 16 if(last == '-') ans = -ans; 17 return ans; 18 } 19 inline void write(ll x) 20 { 21 if(x < 0) x = -x, putchar('-'); 22 if(x >= 10) write(x / 10); 23 putchar(x % 10 + '0'); 24 } 25 int N; 26 stack<ll> s; 27 ll in[maxn]; 28 ll h[maxn],out[maxn]; 29 int main() 30 { 31 N = read(); 32 _for(i,1,N+1) 33 { 34 h[i] = read(); 35 out[i] = read(); 36 } 37 _for(i,1,N+1) 38 { 39 while(!s.empty() && h[s.top()] < h[i]) 40 { 41 in[i] += out[s.top()]; 42 s.pop(); 43 } 44 if(!s.empty()) 45 in[s.top()] += out[i]; 46 s.push(i); 47 } 48 ll ans = 0; 49 _for(i,1,N+1) 50 ans = max(ans,in[i]); 51 write(ans); 52 return 0; 53 }