Pagini recente » Cod sursa (job #2709623) | Cod sursa (job #262890) | Cod sursa (job #485951) | Cod sursa (job #2036557) | Cod sursa (job #2035404)
#include<fstream>
#include<queue>
#include<algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct oaie {
int dist;
int puf;
int t;
} a[100002];
bool cmp(oaie x, oaie y)
{
if(x.t==y.t)
return x.puf>=y.puf;
return x.t>=y.t;
}
priority_queue <int, vector<int> > heap;
int n, d, l, k, s, i, ii, 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)
{
a[i].t=2147483648;
continue;
}
if(l!=0)
{
a[i].t=(d-a[i].dist)/l+1;
if(a[i].t>tmax)
{
tmax=a[i].t;
continue;
}
}
else
{
a[i].t=d-a[i].dist+1;
if(a[i].t>tmax)
{
tmax=a[i].t;
continue;
}
}
if(a[i].t<0)
a[i].t=2147483648;
}
sort(a+1, a+n+1, cmp);
ii=1;
while(a[ii].t!=tmax)
ii++;
for(i=tmax;i>0;i--)
{
int j=ii;
for(;j<=n;j++)
if(a[j].t==i)
heap.push(a[j].puf);
s+=heap.top();
heap.pop();
}
/*for(i=1;i<=n;i++)
g<<a[i].t<<" ";*/
g<<s;
return 0;
}