Pagini recente » Cod sursa (job #2911685) | Cod sursa (job #1490573) | Cod sursa (job #1042527) | Cod sursa (job #1487761) | Cod sursa (job #2568885)
#include <fstream>
#include <algorithm>
#include <queue>
#define Nmax 1000005
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct nod
{
int x, y;
}v[Nmax];
bool cmp(const nod a, const nod b)
{
return a.x < b.x;
}
int n, k, i, lim, val, s = 0, maxx = 0, d;
priority_queue < int > Q;
int main()
{
f >> n >> d >> k;
for(i = 1; i <= n; i++)
f >> v[i].x >> v[i].y;
sort(v + 1, v + n + 1, cmp);
i = 1;
for(lim = 0; lim <= d && i <= n; lim = lim + k)
{
maxx = 0;
for(i = i; i <= n && v[i].x <= lim; i ++)
Q.push(v[i].y);
if(!Q.empty())
{
val = Q.top();
s += val;
Q.pop();
}
}
g << s;
return 0;
}