Pagini recente » Cod sursa (job #1276424) | Cod sursa (job #2356396) | Cod sursa (job #2962003) | Cod sursa (job #160558) | Cod sursa (job #599717)
Cod sursa(job #599717)
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
long n,x,l;
struct LUP
{
long d,a;
};
vector <LUP> z;
queue <long> c;
inline bool cmp (LUP v , LUP w)
{
if (v.d>w.d)
return true;
if (v.d<w.d)
return false;
if (v.d==w.d)
if (v.a>w.a)
return true;
else
return false;
}
void read ()
{
long i;
LUP temp;
scanf("%ld%ld%ld",&n,&x,&l);
for (i=1;i<=n;i++)
{
scanf("%ld%ld",&temp.d,&temp.a);
z.push_back(temp);
}
sort(z.begin(),z.end(),cmp);
}
void rez()
{
long i,u=0,cu;
long long s=0,sc;
vector <LUP> :: iterator it;
LUP temp;
for (it=z.begin();it!=z.end();++it)
{
temp=*it;
if (temp.d+l*u<=x) // t=(x-temp.d)/l
{
u++;
c.push(temp.a);
s=s+(long long)temp.a;
}
else
if (!c.empty())
if(temp.a>c.back())
{
s=(long long)s-c.back()+temp.a;
c.pop();
c.push(temp.a);
}
}
printf("%lld\n",s);
}
int main()
{
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
read();
rez();
return 0;
}