Pagini recente » Cod sursa (job #913711) | Cod sursa (job #1251810) | Cod sursa (job #1200336) | Cod sursa (job #623983) | Cod sursa (job #3165201)
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
#define MaxN 100000
struct oaie
{
int dist, lana;
};
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, res=0, cnt=0, a, b, j;
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++;
}
}
for(i=maxrounds; i>=0; i--)
{
for(j=0; j<cnt; j++)
{
if(v[j].dist==i)
{
pq.push(v[j].lana);
}
}
if(pq.size()>0)
{
res+=pq.top();
pq.pop();
}
}
out<<res;
return 0;
}