Pagini recente » Cod sursa (job #1637679) | Cod sursa (job #1679675) | Cod sursa (job #491254) | Cod sursa (job #1352058) | Cod sursa (job #1106716)
#include<fstream>
using namespace std;
#include<algorithm>
#include<set>
ifstream f("lupu.in");
ofstream g("lupu.out");
#define nmax 100010
long long sol;
int n,x,d;
struct elem
{
int ln;
int x;
} oi[nmax];
struct cmp
{
bool operator()(const int &a,const int &b)
{
return a>b;
}
};
bool comp (elem a,elem b)
{
return a.x>b.x;
};
multiset <int,cmp> h;
multiset <int,cmp> h_mic;
int main()
{
f>>n>>x>>d;
for(int i=1;i<=n;i++)
{
f>>oi[i].x>>oi[i].ln;
h.insert(oi[i].ln);
if(oi[i].x>x-d && oi[i].x<=d)
h_mic.insert(oi[i].ln);
}
sort(oi+1,oi+n+1,comp);
int k=1;
while(x-d>0)
{
if(*h.begin()==*h_mic.begin())
sol+=*h.begin();
else
sol+=*h_mic.begin();
h_mic.clear();
while(oi[k].x>x-d)
h.erase(h.find(oi[k++].ln));
x-=d;
}
g<<sol<<'\n';
return 0;
}