Pagini recente » Cod sursa (job #1473232) | Cod sursa (job #1034087) | Cod sursa (job #1143864) | Cod sursa (job #2954574) | Cod sursa (job #3194952)
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
long long n, dist, scr, sumi;
pair<long long, long long> a[100005];
priority_queue<long long> H;
int main()
{
f >> n >> dist >> scr;
for(int i = 1; i <= n; i++)
{
long long x, y;
f >> x >> y;
a[i].first = (dist - x) / scr;
a[i].second = y;
}
sort(a + 1, a + n + 1);
long long x = a[n].first, p = n;
while(x >= 0)
{
while(p && x <= a[p].first)
H.push(a[p].second), p --;
if(!H.empty())
sumi += H.top(), H.pop();
x --;
}
g << sumi;
return 0;
}