Pagini recente » Cod sursa (job #460770) | Rating Ceapa Andrei (Shadow_blade) | Monitorul de evaluare | Cod sursa (job #1306940) | Cod sursa (job #2418096)
#include <bits/stdc++.h>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int N = 1e5+5;
pair<int,int> v[N];
priority_queue<int> q;
int k;
int main()
{
int n,x,l;
long long s = 0;
in >> n >> x >> l;
for (int i = 1; i<=n; i++)
{
int a,d;
in >> d >> a;
if (d<=x)
v[++k] = {(x-d)/l+1,a};
}
sort(v+1,v+k+1);
int t = v[k].first;
for (int pas = t; pas>=1; pas--)
{
while (k>=1 && v[k].first == pas)
{
q.push(v[k].second);
k--;
}
if (!q.empty())
{
s+=q.top();
q.pop();
}
}
out << s;
}