AcWing 145. 超市
原题链接
简单
作者:
自由周某
,
2020-08-31 13:14:05
,
所有人可见
,
阅读 471
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
const int N = 1e4 + 5;
bool cmp(PII&a, PII&b){
return a.second < b.second;
}
int main(){
int n;
while(cin >> n){
priority_queue<int , vector<int>, greater<int>> heap;
vector<PII> t;
int res = 0;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
t.push_back({a, b});
}
sort(t.begin(), t.end(), cmp);
for(auto p : t){
int x = p.first, y = p.second;
heap.push(x);
if(heap.size() > y) heap.pop();
}
while(heap.size()){
res += heap.top();
heap.pop();
}
cout << res << endl;
}
return 0;
}