Pagini recente » Istoria paginii home | Cod sursa (job #3233685) | Painting | Cod sursa (job #2193168) | Cod sursa (job #1291630)
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#define MAX_N 100005
using namespace std;
typedef struct o_oaie {
int d;
int a;
int t;
}oaie;
oaie o[MAX_N];
priority_queue<int> myq;
bool cmp(oaie c, oaie b) {
return c.t < b.t;
}
int main()
{
FILE *fin = fopen("lupu.in", "r");
FILE *fout = fopen("lupu.out", "w");
int n, x, l;
fscanf(fin, "%d %d %d", &n, &x, &l);
for(int i = 0; i < n; ++i) {
fscanf(fin, "%d %d", &o[i].d, &o[i].a);
o[i].t = (x - o[i].d)/l;
}
sort(o, o + n, cmp);
int tmax = o[n - 1].t;
int crt = n - 1;
long long s = 0;
for(int i = tmax; i >= 0; --i) {
while(o[crt].t == i) {
myq.push(o[crt].a);
--crt;
}
if(!myq.empty()) {
s += (long long)myq.top();
myq.pop();
}
}
fprintf(fout, "%lld", s);
}