Pagini recente » Cod sursa (job #2550028) | Cod sursa (job #1432112) | Cod sursa (job #2204240) | Cod sursa (job #2027773) | Cod sursa (job #2681120)
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cctype>
using namespace std;
const int INF = INT_MAX;
const int NMAX = 100000;
char buffer[1 << 17];
int sz = (1 << 17), crs = (1 << 17);
void get_int(int &n)
{
for( ; crs < sz && !isdigit(buffer[crs]) ; crs ++);
if(crs == sz)
{
fread(buffer, sz, 1, stdin);
for(crs = 0 ; crs < sz && !isdigit(buffer[crs]) ; crs ++);
}
n = 0;
for( ; crs < sz && isdigit(buffer[crs]) ; crs ++)
n = n * 10 + buffer[crs] - '0';
if(crs == sz)
{
fread(buffer, sz, 1, stdin);
for(crs = 0 ; crs < sz && isdigit(buffer[crs]) ; crs ++)
n = n * 10 + buffer[crs] - '0';
}
}
struct lupu
{
int x, y;
lupu(int tx = 0, int ty = 0): x(tx), y(ty) {}
};
lupu v[NMAX + 5];
int cmp(lupu a, lupu b)
{
return a.x > b.x;
}
int main()
{
freopen("lupu.in", "r", stdin);
freopen("lupu.out", "w", stdout);
int n, r, l, i, j, x, y, cnt, maxim;
long long s = 0;
get_int(n);
get_int(r);
get_int(l);
maxim = 0;
for(i = 1 ; i <= n ; ++ i)
{
get_int(x);
get_int(y);
v[i] = {(r - x) / l + 1, y};
maxim = max(maxim, (r - x) / l + 1);
}
sort(v + 1, v + n + 1, cmp);
priority_queue <int> pq;
j = 1;
for(i = maxim ; i >= 1 ; i --)
{
for( ; j <= n && v[j].x == i ; j ++)
pq.push(v[j].y);
if(!pq.empty())
{
s += pq.top();
pq.pop();
}
}
printf("%lld\n", s);
return 0;
}