Pagini recente » Cod sursa (job #918956) | Cod sursa (job #1347732) | Cod sursa (job #816200) | Cod sursa (job #1383282) | Cod sursa (job #3005111)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct Sheep
{
bool operator()( pair < int, int > A, pair < int, int > B)
{
if(A.first != B.first)
return A.first < B.first;
else
return A.second > B.second;
}
};
priority_queue < int, vector < pair < int, int > >, Sheep > Q;
int N, L, D;
void Read()
{
fin >> N >> L >> D;
for(int i = 1; i <= N; ++ i)
{
int A, B;
fin >> A >> B;
Q.push(make_pair(B, A));
}
}
void Task()
{
int R = D;
long long SUM = 0;
SUM += Q.top().first;
Q.pop();
while(!Q.empty())
{
if(Q.top().second + D <= L)
{
D += R;
SUM += Q.top().first;
}
Q.pop();
}
fout << SUM;
}
int main()
{
Read();
Task();
return 0;
}