zoukankan      html  css  js  c++  java
  • 洛谷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 } 
  • 相关阅读:
    WPF基础篇之静态资源和动态资源
    15-Node-数据库
    15-Node
    12-Git
    总-S04-03 项目-大事件
    00-PHP难点
    08-PHP基础
    15-ES6
    16-Vue-webpack
    00-Web难点
  • 原文地址:https://www.cnblogs.com/yu-xing/p/10162927.html
Copyright © 2011-2022 走看看