Pagini recente » Autentificare | Cod sursa (job #2019750) | Cod sursa (job #2846880) | Cod sursa (job #1352664) | Cod sursa (job #3241618)
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int nmax = 100005;
struct oaie{
int lana, timp;
bool operator < (const oaie &o){
return timp < o.timp;
}
};
oaie oi[nmax];
priority_queue<int> q;
long long sol;
int n, l, x;
int main(){
f >> n >> x >> l;
for(int i = 1; i <= n; i++){
int d;
f >> d >> oi[i].lana;
oi[i].timp = (x - d) / l;
}
sort(oi + 1, oi + n + 1);
int p = n;
int t = oi[n].timp;
while(t >= 0){
while(p > 0 && oi[p].timp >= t){
q.push(oi[p].lana);
p--;
}
if(!q.empty()){
sol += q.top();
q.pop();
}
t--;
}
g << sol;
return 0;
}