Pagini recente » Cod sursa (job #2891854) | Cod sursa (job #2956969) | Cod sursa (job #1845261) | Cod sursa (job #1857948) | Cod sursa (job #2487489)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("lupu.in");
ofstream g ("lupu.out");
struct sheep
{
int d, w;
};
sheep a[100005];
int n, x, l;
long long sol;
bool cmp (sheep a, sheep b)
{
return a.d < b.d;
}
priority_queue <int> q;
int main()
{
f >> n >> x >> l;
for (int i=1; i<=n; ++i)
{
f >> a[i].d >> a[i].w;
if (a[i].d > x) a[i].d = 0;
else a[i].d = ((x - a[i].d) / l + 1);
}
sort(a+1, a+n+1, cmp);
int val = a[n].d;
for (int ind = n; ind >= 1 && val; --val)
{
while (val == a[ind].d && ind > 0)
{
q.push(a[ind].w);
ind--;
}
if (!q.empty())
{
sol = sol + 1LL * q.top();
q.pop();
}
else val = a[ind].d + 1;
}
g << sol << '\n';
return 0;
}