Pagini recente » Cod sursa (job #2226952) | Cod sursa (job #490086) | Cod sursa (job #937194) | Cod sursa (job #1138988) | Cod sursa (job #1735358)
#include <algorithm>
#include <fstream>
#define f first
#define s second
using namespace std;
int n,x,l,tmx,*parent;
pair<int,int> v[100005];
bool check(int p) {
int st=p;
while(parent[p]!=p&&p!=0)
p=parent[p];
if(p<=0)
return false;
while(st!=p&&st!=0) {
int last=st;
st=parent[st];
parent[last]=p-1;
}
parent[p]=p-1;
return true;
}
int main()
{
ifstream fin("lupu.in");
ofstream fout("lupu.out");
fin>>n>>x>>l;
for(int i=1;i<=n;i++) {
fin>>v[i].s>>v[i].f;
v[i].s=(x-v[i].s)/l+1;
tmx=max(tmx,v[i].s);
}
parent=new int[tmx+5];
for(int i=1;i<=tmx;i++)
parent[i]=i;
sort(v+1,v+n+1);
long long int ans=0;
for(int i=n;i>=1;i--)
if(check(v[i].s))
ans+=v[i].f;
fout<<ans<<'\n';
return 0;
}