欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-06-04 18:14:07
...

Educational Codeforces Round 62 (Rated for Div. 2) C
Educational Codeforces Round 62 (Rated for Div. 2) C
贪心思想

#include<iostream>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
const int N=2e6+10;
typedef long long ll;

int n,k;
pair<int ,int >a[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].second>>a[i].first;
    }
    sort(a,a+n);
    ll sum=0;
    ll res=0;
    set<pair<int ,int > >s;
    for(int i=n-1;i>=0;i--)
    {
        s.insert(make_pair(a[i].second,i));//再次排序将长度短的歌曲弹出
        sum+=a[i].second;
        while(s.size()>k)
        {
            set<pair<int ,int> >::iterator it=s.begin();
            sum-=it->first;
            s.erase(it);
        }
        res=max(res,sum*a[i].first);
    }
    cout<<res<<endl;
}