Pagini recente » Cod sursa (job #1262970) | Cod sursa (job #1478706) | Cod sursa (job #481081) | Cod sursa (job #822253) | Cod sursa (job #1973016)
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int NMax=100005;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int N,X,L;
long long Sol;
vector < pair<int,int> > V;
priority_queue <int> PQ;
void Read()
{
fin>>N>>X>>L;
for(int i=1;i<=N;++i)
{
int a,b;
fin>>a>>b;
a = ( X - a ) / L;
V.push_back(make_pair(a,b));
}
}
bool Compare(pair<int,int> A,pair<int,int> B)
{
return (A.first > B.first);
}
void Solve()
{
sort(V.begin(),V.end(),Compare);
int i=0;
for(int k=V[0].first; k>=0; k--)
{
while(V[i].first ==k && i<(int) V.size())
{
PQ.push(V[i].second);
i++;
}
if(!PQ.empty())
{
Sol += PQ.top();
PQ.pop();
}
}
}
void Print()
{
fout<<Sol<<"\n";
}
int main()
{
Read();
Solve();
Print();
return 0;
}