Pagini recente » Cod sursa (job #2736152) | Cod sursa (job #367128) | Cod sursa (job #94855) | Cod sursa (job #1907175) | Cod sursa (job #1849974)
#include <bits/stdc++.h>
using namespace std;
struct str{
int l,t;
}a[100005];
int tp,tc;
int cmp(str,str);
priority_queue <long long> q;
int n,dmax,l;
long long s;
int main(){
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
scanf("%d%d%d",&n,&dmax,&l);
for (int i=1;i<=n;i++){
int d;
scanf("%d%d",&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;
long long 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++;
}
}
if (!q.empty()){
s+=q.top();
}
printf("%lld",s);
}
int cmp(str a,str b){
return a.t>b.t;
}