Playlist(优先队列)

2020-09-11 14:53:51 浏览数 (1)

代码语言:javascript复制
#include<bits/stdc  .h>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
using namespace std;
#define N 300005
struct node
{
    ll x,y;
} se[N];
bool cmp(node a,node b)
{
    return a.y>b.y;
}
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    priority_queue<ll,vector<ll>,greater<ll> >q;
    ll sum=0;
    ll ans=0;
    for(ll i=0; i<n; i  )
    {
        scanf("%lld%lld",&se[i].x,&se[i].y);
    }
    sort(se,se n,cmp);//因为乘se[i].b,所以先对其排序
    for(int i=0; i<n; i  )
    {
        q.push(se[i].x);
        sum =se[i].x;
        if(q.size()>m)
        {//首先不能保证前m乘积个一定最大,
            sum-=q.top();
            q.pop();
        }
        ans=max(ans,sum*se[i].y);
//        printf("%lld*******n",ans);
    }
    printf("%lldn",ans);
    return 0;
}

0 人点赞