Pagini recente » Cod sursa (job #2618600) | Cod sursa (job #2422623) | Clasamentul arhivei de probleme | Clasamentul arhivei de probleme | Cod sursa (job #2031677)
#include<fstream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, X, L, nr, pos;
long long sol;
pair<int,int> v[100005];
priority_queue< int, vector<int>, less<int> > q;
inline int cmp( const pair<int,int> &a, const pair<int,int> &b ){
if( a.first == b.first )
return a.second > b.second;
return a.first > b.first;
}
int main(){
fin >> n >> X >> L;
for( int i = 1; i <= n; i++ ){
fin >> v[i].first >> v[i].second;
v[i].first = (X - v[i].first) / L;
nr = max( v[i].first, nr );
}
sort( v + 1, v + n + 1, cmp );
pos = 1;
while( pos <= n && nr >= 0 ){
while( pos <= n && v[pos].first == nr )
q.push( v[pos].second ), pos++;
if( !q.empty() ){
sol += q.top();
q.pop();
}
nr--;
}
fout << sol << "\n";
return 0;
}