Pagini recente » Cod sursa (job #1156977) | Cod sursa (job #2442058)
#include <fstream>
#include <set>
#include <algorithm>
#define nmax 100001
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct oaie{
int timp;
int lana;
bool operator<(const oaie& a) {
return this->timp<a.timp;
}
};
int main(){
int n, x, l, i, nr, k=0, a, b;
long long total=0;
multiset<int> mp;
oaie oita[100005];
f>>n>>x>>l;
for(i=1;i<=n;i++){
f>>a>>b;
if(a<=x){
k++;
oita[k].timp=(x-a)/l+1;
oita[k].lana=b;
}
}
sort(oita+1,oita+k+1);
int t=oita[k].timp;
nr=k;
for(i=t;i>=1;i--){
while(nr>=1 && oita[nr].timp==i){
mp.insert(oita[nr].lana);
nr--;
}
if(!mp.empty()){
total+=*(mp.rbegin());
mp.erase(--mp.end());
}
}
g<<total<<" ";
return 0;
}