Pagini recente » Cod sursa (job #3360039) | Cod sursa (job #3360023) | Cod sursa (job #3360049) | Cod sursa (job #3360050) | Cod sursa (job #3360013)
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n,x,l;
vector<pair<int, int>> sheep;
priority_queue<int> heap;
long long int ans;
void read()
{
fin >> n >> x >> l;
for(int i = 0; i < n; ++i){
int d,a;
fin >> d >> a;
int bucket = (x - d) / l;
if(bucket >= 0){
sheep.push_back(make_pair(bucket, a));
}
}
}
void solve()
{
sort(sheep.begin(), sheep.end());
for(int i = sheep.size() - 1; i >= 0; --i){
if(i < sheep.size() - 1 && sheep[i].first != sheep[i + 1].first){
if(!heap.empty()){
ans += heap.top();
heap.pop();
}
}
heap.push(sheep[i].second);
}
if(!heap.empty()){
ans += heap.top();
heap.pop();
}
fout << ans;
}
int main()
{
read();
solve();
return 0;
}