Pagini recente » Cod sursa (job #400081) | Cod sursa (job #2752602) | Cod sursa (job #1169905) | Cod sursa (job #2965509) | Cod sursa (job #3165204)
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
#define MaxN 100000
struct oaie
{
int dist, lana;
};
bool cmp(const oaie& a, const oaie& b)
{
return a.dist>b.dist;
}
oaie v[MaxN];
priority_queue <int> pq;
int main()
{
ifstream in("lupu.in");
ofstream out("lupu.out");
int n, x, l, rounds=0, i, maxrounds, cnt=0, a, b, j;
long long int res=0;
in>>n>>x>>l;
for(i=0; i<n; i++)
{
in>>a>>b;
if(a<=x)
{
v[cnt].dist=(x-a)/l;
if(v[cnt].dist>maxrounds) maxrounds=v[cnt].dist;
v[cnt].lana=b;
cnt++;
}
}
sort(v, v+cnt, cmp);
j=0;
for(i=maxrounds; i>=0; i--)
{
while(j<cnt && v[j].dist==i)
{
pq.push(v[j].lana);
j++;
}
if(pq.size()>0)
{
res+=pq.top();
pq.pop();
}
}
out<<res;
return 0;
}