Pagini recente » Cod sursa (job #1586640) | Cod sursa (job #2247103) | Cod sursa (job #1531648) | Cod sursa (job #2174080) | Cod sursa (job #2681092)
#include <cstdio>
#include <algorithm>
#include <set>
#include <climits>
#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)
{
if(a.y == b.y)
return a.x > b.x;
return a.y > b.y;
}
int main()
{
freopen("lupu.in", "r", stdin);
freopen("lupu.out", "w", stdout);
int n, r, l, i, x, y, cnt, maxim;
long long sum = 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);
}
maxim = min(maxim, NMAX);
sort(v + 1, v + n + 1, cmp);
set <int> s;
set <int>::iterator it;
for(i = 1 ; i <= maxim ; ++ i)
s.insert(i);
s.insert(INF);
for(i = 1 ; i <= n ; ++ i)
{
if(v[i].x > 100000)
{
sum += v[i].y;
continue;
}
it = lower_bound(s.begin(), s.end(), v[i].x);
if(it != s.begin() && (*it) != v[i].x)
it --;
if(*it <= v[i].x)
{
sum += v[i].y;
s.erase(it);
}
}
printf("%lld\n", sum);
return 0;
}