Pagini recente » Cod sursa (job #601502) | Cod sursa (job #53505) | Cod sursa (job #367107) | Cod sursa (job #150820) | Cod sursa (job #416389)
Cod sursa(job #416389)
#include <fstream>
#include <set>
using namespace std;
ifstream f1 ("lupu.in");
ofstream f2 ("lupu.out");
multiset<int> h;
struct l {int x, y;};
l t[100001];
int a[100001],b[100001],tmax;
int compar (const void *p, const void *q)
{
l x=*(l*)p, y=*(l*)q;
if (x.x>y.x) return 1;
if (x.x<y.x) return -1;
return 0;
}
int main()
{
int n,x1,l,i,j,poz,sol=0;
f1>>n>>x1>>l;
for (i=1; i<=n; i++)
{
f1>>b[i]>>a[i];
if (x1>=b[i]) {t[i].x=(x1-b[i])/l+1; t[i].y=i;}
if (t[i].x>tmax) tmax=t[i].x;
}
qsort (t+1,n,sizeof(t[0]),compar);
poz=n;
for (j=tmax; j>=1; j--)
{
while (t[poz].x==j) {h.insert(a[t[poz].y]); poz--;}
multiset<int>:: reverse_iterator it;
it=h.rbegin();
sol+=*it;
i=*it;
h.erase(i);
}
f2<<sol<<"\n";
return 0;
}