Pagini recente » Cod sursa (job #604998) | Cod sursa (job #1338046) | Cod sursa (job #1579944) | Cod sursa (job #2055247) | Cod sursa (job #1266612)
#include <fstream>
#include <queue>
#include <algorithm>
#define NMax 100001
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
int n, x, l, i, j, el, k, ind, 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;
if (el<=x) {
f>>o[++k].lana;
o[k].t=(x-el)/l+1;
}
}
sort (o+1, o+n+1, cmp);
ind=1;
k=1;
for (i=o[1].t; i>=1; i--) {
while (o[k].t==i) {
H.push(o[k].lana);
k++;
}
cantitate+=H.top();
H.pop();
}
g<<cantitate;
return 0;
}