洛谷P1901 发射站
1 #include<cstdio> 2 #include<algorithm> 3 #include<stack> 4 #include<cctype> 5 using namespace std; 6 typedef long long LL; 7 struct node{ 8 int id; 9 LL h; 10 LL e; 11 node(int id=0,LL h=0,LL e=0):id(id),h(h),e(e){ 12 } 13 }; 14 LL sum[1000005]; 15 stack<node> q; 16 LL n,tmph,tmpe; 17 int main() 18 { 19 scanf("%lld",&n); 20 for(int i=1;i<=n;i++) 21 { 22 scanf("%lld%lld",&tmph,&tmpe); 23 while(!q.empty()&&tmph>q.top().h) 24 { 25 sum[i]+=q.top().e; 26 q.pop(); 27 } 28 if(!q.empty()) sum[q.top().id]+=tmpe; 29 q.push(node(i,tmph,tmpe)); 30 } 31 printf("%lld",*max_element(sum+1,sum+1+n)); 32 return 0; 33 }