Pagini recente » Cod sursa (job #3279935) | Cod sursa (job #2398290) | Cod sursa (job #1850391) | Cod sursa (job #2434308) | Cod sursa (job #1067763)
#include <algorithm>
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
typedef long long i64;
const int nmax= 100000;
struct str {
int x, y;
};
bool comp ( str x, str y ) {
return x.x<y.x;
}
str v[nmax+1];
priority_queue <int> q;
int main( ) {
int n, x, l;
fin>>n>>x>>l;
for ( int i= 1; i<=n; ++i ) {
fin>>v[i].x>>v[i].y;
v[i].x= (x-v[i].x+l)/l;
}
sort(v+1, v+n+1, comp);
i64 sol= 0;
int i= n, t= v[i].x;
for ( ; t>0; --t ) {
while ( i>0 && v[i].x==t ) {
q.push(v[i].y);
--i;
}
if ( !q.empty() ) {
sol+= q.top();
q.pop();
} else if ( i>0 ) {
t= v[i].x+1;
}
}
fout<<sol<<"\n";
return 0;
}