Pagini recente » Cod sursa (job #2160870) | Cod sursa (job #1366608) | Cod sursa (job #3147272) | Cod sursa (job #1604249) | Cod sursa (job #3005032)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct Sheep
{
bool operator()(const pair < int, int > &A, const pair < int, int > &B)
{
if(A.first != B.first)
return A.first > B.first;
else
return A.second < B.second;
}
};
multiset < 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.insert(make_pair(B, A));
}
}
void Task()
{
int R = D;
long long SUM = 0;
for(multiset < pair < int, int > > :: iterator I = Q.begin(); I != Q.end(); I ++)
{
if(I == Q.begin())
SUM += I -> first;
else
if(I -> second + D <= L)
{
D += R;
SUM += I -> first;
}
}
fout << SUM;
fin.close();
fout.close();
}
int main()
{
Read();
Task();
return 0;
}