Pagini recente » Cod sursa (job #3247801) | Cod sursa (job #1190488) | Cod sursa (job #2539806) | Cod sursa (job #474622) | Cod sursa (job #2040194)
#include<fstream>
#include<queue>
#include<algorithm>
#define inf 2147483648
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, l, k, i, ii, t[100002], tmax;
long long s, d;
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=inf;
continue;
}
if(l!=0)
{
a[i].dist=(d-a[i].dist)/l+1;
if(a[i].dist<0)
{
a[i].dist=inf;
continue;
}
}
if(a[i].dist>tmax)
tmax=a[i].dist;
}
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;
}