Educational Codeforces Round 62 (Rated for Div. 2)C

题目链接 :C. Playlist

 

#include<bits/stdc++.h>
using namespace std;
#define maxn 300005
#define LL long long
#define pii pair<int,int>
const int inf = (int)1e9;
vector<pii>q;
bool cmp(pii a,pii b){
    if(a.second==b.second) return a.first>b.first;
    return a.second>b.second;
}
priority_queue<LL,vector<LL>,greater<LL> >Q;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int j=0;j<n;j++){
        int x,y;
        scanf("%d%d",&x,&y);
        q.push_back(make_pair(x,y));
    }
    sort(q.begin(),q.end(),cmp);
    LL mi =inf,ans = 0,mx = 0;
    for(int j=0;j<n;j++){
        if(Q.size()==m){
            ans -= Q.top();
            Q.pop();
        }
        ans += q[j].first;
        Q.push(q[j].first);
        mx = max(mx,1LL*ans*q[j].second);
    }
    printf("%lld\n",mx);
    return 0;
}

 

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务