Pagini recente » Cod sursa (job #1194240) | Cod sursa (job #394321) | Cod sursa (job #609377) | Cod sursa (job #1673937) | Cod sursa (job #1901370)
#include <fstream>
#include <algorithm>
#include <queue>
#define nmax 100001
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct sheep
{
long long dist;
long long lana;
};
long long n,d,l,maxx,cost;
sheep v[nmax];
priority_queue < long long > behehe;
bool cmp(sheep a, sheep b)
{
return a.dist>b.dist;
}
int main()
{
int i;
fin>>n>>d>>l;
for(i=1;i<=n;i++)
{
fin>>v[i].dist>>v[i].lana;
v[i].dist=(d - v[i].dist) / l + 1 ;
maxx=max(maxx,v[i].dist);
}
sort(v+1,v+n+1,cmp);
i=1;
while(maxx>0)
{
while(v[i].dist==maxx)
{
behehe.push(v[i].lana);
i++;
}
if(!behehe.empty())
{
cost+=behehe.top();
behehe.pop();
}
maxx--;
}
fout<<cost;
fin.close();
fout.close();
return 0;
}