Pagini recente » Clasamentul arhivei ACM | Cod sursa (job #746784) | Cod sursa (job #1332466) | Cod sursa (job #2092305) | Cod sursa (job #152880)
Cod sursa(job #152880)
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <algorithm>
using namespace std;
const int n_max = 100100;
class set_cmp {
public:
bool operator() ( const long long &a, const long long &b ) { return (a > b); };
};
pair <long long , long long > v[n_max];
multiset <long long, set_cmp> s;
long long i, k, n, x, l, t, p;
long long sol = 0, maxim = 0;
int main()
{
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
scanf("%lld %lld %lld\n", &n, &x, &l);
for (i = 1; i <= n; ++ i)
{
scanf("%lld %lld\n", &t, &v[i].second);
v[i].first = (x-t)/l;
// if (v[i].first > maxim) maxim = v[i].first;
}
sort(v+1, v+n+1);
k = n;
for (i = v[n].first; i >= 0; --i)
{
while ( v[k].first == i && k > 0)
{
s.insert(v[k].second);
--k;
}
if (!s.empty())
{
sol += *s.begin();
s.erase(s.begin());
}
}
printf("%lld\n", sol);
return 0;
}