Pagini recente » Cod sursa (job #866155) | Cod sursa (job #2299002) | Cod sursa (job #195076) | Cod sursa (job #1644240) | Cod sursa (job #2964748)
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
#define int long long
const int Nmax = 1e5 + 5;
pair <int ,int> vsheep[Nmax];
bool cmp(pair <int, int> a, pair <int, int> b)
{
return a.first > b.first;
}
signed main()
{
int n, x, l, i;
fin >> n >> x >> l;
for(i = 1; i <= n; i++)
{
fin >> vsheep[i].first >> vsheep[i].second;
vsheep[i].first = (x - vsheep[i].first) / l;
}
sort(vsheep + 1, vsheep + n + 1, cmp);
/*for(i = 1; i <= n; i++)
fout << vsheep[i].first << " " << vsheep[i].second << '\n';*/
int timp = vsheep[1].first, ans = 0;
priority_queue <int> pq;
i = 1;
while(i <= n && timp >= 0)
{
int timpc = vsheep[i].first;
while(vsheep[i].first >= timpc && i <= n)
{
pq.push(vsheep[i].second);
i++;
}
if(!pq.empty())
{
ans += pq.top();
pq.pop();
}
timp--;
}
fout << ans;
return 0;
}