Pagini recente » Profil Djok | Cod sursa (job #847984) | Cod sursa (job #828106) | Cod sursa (job #1720846) | Cod sursa (job #848235)
Cod sursa(job #848235)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
class cmp
{
public:
inline bool operator()(const pair<int, int> &A, const pair<int, int> &B)
{
return A.first > B.first;
}
inline bool operator()(const int &A, const int &B)
{
return A < B;
}
};
int N, DMax, D, GG;
vector< pair<int, int> > A;
vector<int> H;
priority_queue<int, vector<int>, cmp> P;
int main()
{
fin >> N >> DMax >> D;
A.resize(N + 3, make_pair(0, 0));
for (int i = 1; i <= N; ++i)
{
fin >> A[i].first >> A[i].second;
if (A[i].first > DMax) A[i].first = 0;
else A[i].first = (DMax - A[i].first) / D + 1;
}
sort(A.begin() + 1, A.end(), cmp());
for (int i = 1; i <= N; )
{
if (A[i].first == 0) break;
//for (int foo = i; A[foo].first == A[i].first && i <= N; H.push_back(A[i].second), push_heap(H.begin(), H.end(), cmp()), ++i);
//if (H.size()) GG += H.front(), pop_heap(H.begin(), H.end(), cmp()), H.pop_back();
for (int foo = i; A[foo].first == A[i].first && i <= N; P.push(A[i].second), ++i);
if (!P.empty()) GG += P.top(), P.pop();
}
fout << GG << '\n';
fout.close();
return 0;
}