Pagini recente » Cod sursa (job #2156915) | Cod sursa (job #772310) | Cod sursa (job #2608821) | Cod sursa (job #460310) | Cod sursa (job #2751802)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
const int NMAX = 1e5;
ifstream fin ("lupu.in");
ofstream fout ("lupu.out");
struct oaie
{
int lana, runda;
};
bool cmp(oaie a, oaie b);
priority_queue<int> myHeap;
oaie arr[NMAX + 1];
int main()
{
int n, x, l, i, dist, r;
long long smax;
fin >> n >> x >> l;
for (i = 0; i < n; i++)
{
fin >> dist >> arr[i].lana;
arr[i].runda = (x - dist) / l + 1;
}
arr[n].runda = 0;
sort(arr, arr + n, cmp);
smax = 0;
i = 0;
for (r = arr[0].runda; r > 0; r--)
{
while (arr[i].runda == r)
{
myHeap.push(arr[i].lana);
i++;
}
if (!myHeap.empty())
{
smax += (long long)myHeap.top();
myHeap.pop();
}
}
fout << smax;
return 0;
}
bool cmp (oaie a, oaie b)
{
return a.runda > b.runda;
}