题解

1 条题解

  • 0
    @ 2022-09-10 15:52:20
    # include <iostream>
    # include <cstdio>
    # include <cstring>
    # include <queue>
    # include <algorithm>
    using namespace std;
    const int maxn=1000100;
    priority_queue <int> q;
    struct homework{
        int time,score;
    }hw[maxn];
    int n;
    int hwcomp(const homework &a,const homework &b)
    {
        return a.time>b.time;
    }
    
    inline void read(int &x)
    {
        char ch=getchar();
        while(ch<'0'||ch>'9') ch=getchar();
        x=0;
        while(ch>='0'&&ch<='9')
        {
            x*=10;x+=ch-'0';
            ch=getchar();
        }
        
    }
    
    int main()
    {int maxt,k=0,ans=0,time,score;
      //  freopen("credits.in","r",stdin);
      //  freopen("credits.out","w",stdout);
        scanf("%d",&n);
        for(int i=0;i<n;++i)
        { read(time);hw[i].time=time;
          read(score);hw[i].score=score;
        }
        sort(hw+0,hw+n,hwcomp);
        maxt=hw[0].time;
        for(int i=maxt;i>=1;--i)
        {
            while(hw[k].time==i&&k<n)
              q.push(hw[k++].score);
            if(!q.empty())
            {ans+=q.top();
             q.pop();
            }
        }
        printf("%d\n",ans);
    }
    
  • 1

信息

ID
1670
难度
6
分类
点击显示
标签
递交数
1
已通过
1
通过率
100%
上传者