Pagini recente » Cod sursa (job #85245) | Cod sursa (job #495755) | Cod sursa (job #2227050) | Cod sursa (job #319203) | Cod sursa (job #3125862)
#include <iostream>
#include <fstream>
#include <queue>
#include <set>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
struct oaie{
int D, A;
bool operator < (const oaie &o) const {
return D < o.D;
}
};
priority_queue<oaie> pq; /// descrescator
priority_queue<int, vector<int>, greater<int> > h;
int N, X, L, D, A, dist = 0;
int main(){
in >> N >> X >> L;
for(int i=1; i<=N; i++){
in >> D >> A;
pq.push({D, A});
}
int t_c = 0;
long long l_totala = 0;
while(!pq.empty()){
oaie o = pq.top();
pq.pop();
if(o.D + t_c * L <= X){
h.push(o.A);
l_totala += o.A;
t_c++;
}
else{
if(!h.empty() && o.A > h.top()){
l_totala += o.A - h.top();
h.pop();
h.push(o.A);
}
}
}
out << l_totala;
}