Pagini recente » Cod sursa (job #3264043) | Cod sursa (job #1740141) | Cod sursa (job #703389) | Cod sursa (job #1810225) | Cod sursa (job #3243707)
#include <iostream>
#include <queue>
#include <fstream>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1e5+1;
ifstream in("lupu.in");
ofstream out("lupu.out");
pair< int, int> H[N];
priority_queue<pair<int,int>, vector<pair<int,int> > > pq;
bool operator<(const pair<int, int>& a, const pair<int, int>& b){
if (a.first < b.first) return true;
if (a.first > b.first) return false;
if (a.second < b.second) return true;
return false;
}
int main(){
int N, X, L;
in >> N >> X >> L;
for(int i = 0; i<N; i++){
int D, F;
in >> D >> F;
D = (X - D) / L;
H[i] = make_pair(D, F);
}
sort(H, H+N);
//for(int i = 0; i<N; i++)
// cout << H[i].first << " " << H[i].second << endl;
int T = H[N-1].first;
int it = N-1;
long long total = 0;
while(T-- >= 0){
while(it >= 0 && H[it].first >= T){
pq.push(H[it]);
it--;
}
if(pq.empty() == false){
total+=pq.top().second;
pq.pop();
}
}
cout << total;
}