题目链接:http://codeforces.com/contest/1140/problem/C
题目大意:给你一个n首歌的t和b,你最多从其中选择k首,使得这k首歌的t值之和乘以这k首歌最小的b值得到的结果最大。
思路:首先你可以对这n首哥的b排序,然后选择大于等于b的最大的t值之和。从后往前扫一遍,sum维护和,用优先队列存储一下当前选择的t值。
代码入下:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+7;
const int maxm = 1e6+7;
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef pair<int,int> P;
P a[maxn];
struct node{
int l;
int r;
bool operator<(const node &x)const{
return l < x.l;
}
};
int main(){
int n,k;
scanf("%d%d",&n,&k);
ll ans = 0;
for(int i = 0;i < n; i++){
scanf("%d%d",&a[i].second,&a[i].first);
}
sort(a,a+n);
ll sum = 0,res = 0;
priority_queue<int,vector<int>,greater<int> > que;
for(int i = n-1;i >= 0; i--){
que.push(a[i].second);
sum += a[i].second;
if(que.size() > k){
sum -= que.top();
que.pop();
}
res = sum*a[i].first;
ans = max(ans,res);
}
cout<<ans<<endl;
return 0;
}