Pagini recente » Cod sursa (job #196926) | Cod sursa (job #1604599) | Cod sursa (job #625556) | Cod sursa (job #2380523) | Cod sursa (job #644601)
Cod sursa(job #644601)
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int> hx;
const int maxN=100005;
pair<int,int> a[maxN];
int n,h,u,s;
bool comp(pair<int,int> v1, pair<int,int> v2)
{
if(v1.first<v2.first)
return true;
else return false;
}
void read()
{
int i,j;
freopen("gutui.in","r",stdin);
freopen("gutui.out","w",stdout);
scanf("%d%d%d",&n,&h,&u);
for(i=1;i<=n;++i)
scanf("%d%d",&a[i].first,&a[i].second);
}
void work()
{
int i,da,hh;
sort(a+1,a+n+1,comp);
hh=h;
while(hh-u>=a[1].first)
hh-=u;
i=1; da=1;
while(da)
{
if(a[i].first<=hh && i<=n)
{
hx.push(a[i].second);
++i;
}
else
{
if(!hx.empty())
{
s+=hx.top();
hx.pop();
}
hh+=u;
if(hh>h)
da=0;
}
}
}
int main()
{
read();
work();
printf("%d\n",s);
return 0;
}