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