Pagini recente » Cod sursa (job #2293056) | Cod sursa (job #3188764) | Cod sursa (job #2901031) | Cod sursa (job #2321315) | Cod sursa (job #1274366)
#include <fstream>
#include <queue>
#include <algorithm>
#define NMax 100100
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
int n, x, l, i, j, el, k, ind, ln;
long long cantitate;
struct oaie
{
int t;
int lana;
}o[NMax];
priority_queue<int> H;
bool cmp(const oaie &o1, const oaie &o2)
{
return o1.t > o2.t;
}
int main()
{
f>>n>>x>>l;
for (i=1; i<=n; i++) {
f>>el>>ln;
if (el<=x) {
o[++k].lana=ln;
o[k].t=(x-el)/l;
}
}
sort (o+1, o+k+1, cmp);
ind=1;
int sz=k;
k=1;
for (i=o[1].t; i>=0; i--) {
while (o[k].t==i && k < sz) {
H.push(o[k].lana);
k++;
}
if (!H.empty()) {
cantitate+=1LL*H.top();
H.pop();
}
}
g<<cantitate;
return 0;
}