Pagini recente » Cod sursa (job #435407) | Cod sursa (job #3270794) | Cod sursa (job #3238750) | Cod sursa (job #2166159) | Cod sursa (job #1403915)
#include<fstream>
#include<algorithm>
#include<set>
using namespace std;
#define Nmax 100003
ifstream cin("lupu.in");
ofstream cout("lupu.out");
int n, i, H, pas, h;
long long RS;
set<int> s;
struct el
{
int dist, cost;
};
el a[Nmax];
bool cmp(el a, el b)
{
return a.dist < b.dist;
}
set<int> :: iterator it;
int main()
{
cin>>n>>H>>pas;
for (i=1;i<=n;i++)
cin>>a[i].dist>>a[i].cost;
sort(a+1,a+n+1,cmp);
h=H;
while (h>=a[1].dist) h-=pas;
h+=pas;
for (i=1 ; h<=H; h+=pas )
{
while (i<=n && a[i].dist<=h) s.insert(a[i].cost),i++;
if (s.size()) {
it = s.end(); it--;
RS += *it;
s.erase(it);
}
}
cout<<RS;
return 0;
}