Pagini recente » Cod sursa (job #280778) | Cod sursa (job #2261219) | Cod sursa (job #3292360) | Cod sursa (job #2347143) | Cod sursa (job #2918270)
#include <bits/stdc++.h>
#define nmax 100003
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
vector<int> v[nmax];
int n,x,l;
int h[nmax],k;
int getpoz(const int &nr)
{
return max(0,(x-nr)/l+1);
}
bool cmp(const int &a, const int &b)
{
return a>b;
}
int main()
{
f>>n>>x>>l;
int a,b;
int mx=0;
for(int i=0;i<n;i++)
{
f>>a>>b;
a=getpoz(a);
v[a].push_back(b);
mx=max(mx,a);
}
for(int i=1;i<=mx;i++)
{
sort(v[i].begin(),v[i].end(),cmp);
for(int j=0;j<min(i,(int)(v[i].size()));j++)
{
//cout<<i<<','<<j<<','<<v[i][j]<<'\n';
if(k<i)
{
h[k++]=v[i][j];
push_heap(h,h+k,cmp);
}
else if(v[i][j]>h[0])
{
pop_heap(h,h+k,cmp);
h[k-1]=v[i][j];
push_heap(h,h+k,cmp);
}
}
}
long long ans=0;
for(int i=0;i<k;i++)
{
//cout<<h[i]<<' ';
ans+=(long long)(h[i]);
}
g<<ans;
return 0;
}