Pagini recente » Cod sursa (job #2809913) | Cod sursa (job #2149911) | Cod sursa (job #2636722) | Cod sursa (job #2664094) | Cod sursa (job #3142102)
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int nmax = 100005;
struct oi{
int wool, dist;
}A[nmax];
int n, prey, scared, sol;
priority_queue<int> H;
bool cmp(oi x, oi y){
if(x.dist != y.dist)
return (x.dist < y.dist);
else
return (x.wool < y.wool);
}
int main()
{
f >> n >> prey >> scared;
for(int i = 1; i <= n; i ++)
{
int x;
f >> x >> A[i].wool;
A[i].dist = (prey - x) / scared;
}
sort(A + 1, A + n + 1, cmp);
int x = A[n].dist, p = n;
while(x >= 0)
{
while(p && A[p].dist >= x){
H.push(A[p].wool);
p --;
}
if(!H.empty())
{
sol += H.top();
H.pop();
}
x --;
}
g << sol;
return 0;
}