Pagini recente » Cod sursa (job #807264) | Cod sursa (job #946220) | Cod sursa (job #791081) | Cod sursa (job #2755107) | Cod sursa (job #916124)
Cod sursa(job #916124)
#include<fstream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>
#define MAX_SIZE 100005
FILE *f=fopen("lupu.in","r");
FILE *g=fopen("lupu.out","w");
using namespace std;
pair <int,int> o[MAX_SIZE];
int n,dist,l;
long long RES;
priority_queue <int> bst;
int main()
{
fscanf(f,"%d%d%d",&n,&dist,&l);
int a,b;
for(int i(0); i <n; ++i )
{
fscanf(f,"%d%d",&a,&b);
o[i].first=(dist-a)/l+1;
o[i].second=b;
}
sort(o,o+n);
reverse(o,o+n);
int k=o[0].first;
int i=0;
while( k )
{
while( i < n && k == o[i].first )
{
bst.push(o[i].second);
i++;
}
if(bst.size())
{
RES+=bst.top();
bst.pop();
}
k--;
}
fprintf(g,"%lld\n",RES);
fclose(f);
fclose(g);
return 0;
}