Pagini recente » Cod sursa (job #576955) | Cod sursa (job #2413917) | Cod sursa (job #2642586) | Cod sursa (job #317195) | Cod sursa (job #2040161)
#include<fstream>
#include<queue>
#include<algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct oaie
{
long long dist;
int puf;
} a[100002];
bool cmp(oaie x, oaie y)
{
return x.dist>y.dist;
}
int n, d, l, k, s, i, ii, t[100002], tmax;
priority_queue <int, vector<int> > heap;
int main()
{
f>>n>>d>>l;
for(i=1;i<=n;i++)
{
f>>a[i].dist>>a[i].puf;
if(a[i].dist>d)
{
a[i].dist=2147483648;
continue;
}
if(l!=0)
{
a[i].dist=(d-a[i].dist)/l+1;
if(a[i].dist>tmax)
{
tmax=a[i].dist;
continue;
}
if(a[i].dist<0)
a[i].dist=2147483648;
}
}
sort(a+1, a+n+1, cmp);
ii=1;
while(a[ii].dist!=tmax)
ii++;
for(i=tmax;i>0;i--)
{
for(;a[ii].dist==i;ii++)
heap.push(a[ii].puf);
if(!heap.empty())
{
s+=heap.top();
heap.pop();
}
}
/*for(i=1;i<=n;i++)
g<<a[i].t<<" ";*/
g<<s;
return 0;
}