Pagini recente » Cod sursa (job #676883) | Cod sursa (job #2961330) | Profil CarlaDiana | Diferente pentru utilizator/stargold2 intre reviziile 190 si 191 | Cod sursa (job #1849969)
#include <bits/stdc++.h>
using namespace std;
struct str{
int l,t;
}a[100005];
int tp,tc;
int cmp(str,str);
priority_queue <int> q;
int n,dmax,l,s;
int main(){
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
cin>>n>>dmax>>l;
for (int i=1;i<=n;i++){
int d;
cin>>d>>a[i].l;
if (d>dmax){
a[i].t=0;
}
else {
a[i].t=(dmax-d)/l+1;
}
}
sort(a+1,a+n+1,cmp);
tp=0;
int i=1;
while (i<=n){
tp=a[i-1].t;
tc=a[i].t;
while (tp>tc&&!q.empty()){
s+=q.top();
q.pop();
tp--;
}
while (a[i].t==tc&&i<=n){
q.push(a[i].l);
i++;
}
}
cout<<s+q.top();
}
int cmp(str a,str b){
return a.t>b.t;
}