Pagini recente » Profil beo1980 | Cod sursa (job #1681794) | Cod sursa (job #1692313) | Cod sursa (job #1110825) | Cod sursa (job #1513117)
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
const int MAX=1000000;
priority_queue<int> pq;
vector<int> v[MAX + 1];
int d, a, i, j, t, n, x, l, maxx;
long long s=0;
int main()
{
freopen("lupu.in", "r", stdin);
freopen("lupu.out", "w", stdout);
scanf("%d%d%d", &n, &x, &l);
for(i = 1; i <= n; i ++)
{
scanf("%d%d", &d, &a);
t = 0;
if(d > x)
t = 0;
else
t = 1 + (x - d) / l;
v[t].push_back(a);
if (t > maxx) maxx = t;
}
for(i = maxx; i > 0; i --)
{
if(!v[i].empty())
{
for(j = 0; j < v[i].size(); j ++)
{
pq.push(v[i][j]);
}
}
if(!pq.empty())
{
s = s + pq.top();
pq.pop();
}
}
printf("%lld\n",s);
return 0;
}