Pagini recente » Cod sursa (job #769998) | Cod sursa (job #1914313) | Cod sursa (job #133829) | Cod sursa (job #1194455) | Cod sursa (job #1044381)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
const int nmax= 100000;
struct str {
int x, y;
} v[nmax+1];
bool comp( str a, str b ) {
if ( a.y==b.y ) {
return a.x>b.x;
} else {
return a.y>b.y;
}
}
bool u[nmax+1];
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);
int k= 1, sol= 0;
for ( int i= 1; i<=n; ++i ) {
if ( v[i].x>=k ) {
for ( int j= v[i].x; j>=1; --j ) {
if ( u[j]==0 ) {
u[j]= 1;
sol+= v[i].y;
++k;
j= 0;
}
}
}
}
fout<<sol<<"\n";
return 0;
}