Pagini recente » Cod sursa (job #144040) | Cod sursa (job #2829348) | Cod sursa (job #190433) | Cod sursa (job #1207830) | Cod sursa (job #2487485)
#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)
{
if (a.d > b.d) return false;
return true;
}
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 ind = n;
for (int val = a[n].d; val>=1; --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;
}