题目链接 :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); ;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 = ,mx = ; ;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); ; }