zoukankan      html  css  js  c++  java
  • Atcoder ABC137D:Summer Vacation(贪心)

    D - Summer Vacation


    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 400 points

    Problem Statement

    There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of Bi after Ai days from the day you do it.

    You can take and complete at most one of these jobs in a day.

    However, you cannot retake a job that you have already done.

    Find the maximum total reward that you can earn no later than M days from today.

    You can already start working today.

    Constraints

    • All values in input are integers.
    • 1N105
    • 1M105
    • 1Ai105
    • 1Bi104

    Input

    Input is given from Standard Input in the following format:

    N  M
    A1 B1
    A2 B2
    
    AN BN
    

    Output

    Print the maximum total reward that you can earn no later than M days from today.

    Sample Input 1

    3 4
    4 3
    4 1
    2 2
    

    Sample Output 1

    5
    

    You can earn the total reward of 5 by taking the jobs as follows:

    • Take and complete the first job today. You will earn the reward of 3 after four days from today.
    • Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.

    题意

    一共有N个任务和M天,一个人一天只能做一个任务,做完任务之后可以在第Ai天拿到Bi的工资,问M天内最多可以拿到多少工资

    思路

    贪心,按照领取工资间隔升序排序

    设置一个优先队列用来储存当前可以做的任务并且可以在M天内拿到工资的任务的钱数,每次取可以拿到的最大值

    代码

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 #define ull unsigned long long
     4 #define ms(a,b) memset(a,b,sizeof(a))
     5 const int inf=0x3f3f3f3f;
     6 const ll INF=0x3f3f3f3f3f3f3f3f;
     7 const int maxn=1e6+10;
     8 const int mod=1e9+7;
     9 const int maxm=1e3+10;
    10 using namespace std;
    11 struct wzy
    12 {
    13     int day,money;
    14 }p[maxn];
    15 bool cmp(wzy u,wzy v)
    16 {
    17     return u.day<v.day;
    18 }
    19 int main(int argc, char const *argv[])
    20 {
    21     ios::sync_with_stdio(false);
    22     cin.tie(0);
    23     int n,m;
    24     cin>>n>>m;
    25     for(int i=0;i<n;i++)
    26         cin>>p[i].day>>p[i].money;
    27     sort(p,p+n,cmp);
    28     priority_queue<int>que;
    29     int ans=0;
    30     int pos=0;
    31     for(int i=1;i<=m;i++)
    32     {
    33         while(p[pos].day<=i&&pos<n)
    34             que.push(p[pos++].money);
    35         if(!que.empty())
    36             ans+=que.top(),que.pop();
    37     }
    38     cout<<ans<<endl;
    39     return 0;
    40 }
  • 相关阅读:
    适配器模式
    自己DIY word2010脚注和尾注没有的格式
    Linux单网卡,双IP,双网关配置,并搭建squid proxy上网
    about using gnuplot
    ReadDirectoryChangesW 函数 流沙
    Jquery easyui 异步树 流沙
    Overlapped I/O 学习 流沙
    jQuery.get(url,[data],[callback]) 流沙
    MsgWaitForMultipleObjectsEx用法 流沙
    Oracle smon_scn_time 表 说明
  • 原文地址:https://www.cnblogs.com/Friends-A/p/11340019.html
Copyright © 2011-2022 走看看