Pagini recente » Cod sursa (job #2375740) | Infoarena Monthly 2014 - Clasament | Cod sursa (job #2488952) | Cod sursa (job #230180) | Cod sursa (job #1259019)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
bool comp (pair<long, long> x, pair<long, long> y)
{
if(x.first < y.first || x.first > y.first)
return x.first>y.first;
return x.second>y.second;
}
class compq
{
public:
bool operator()(pair<long, long> &x, pair<long, long> &y)
{
return x.second<y.second;
}
};
int main()
{
ifstream in ("lupu.in");
ofstream out ("lupu.out");
int n;
long cl=0, x, l, D, L, i, tm=0;
in>>n>>x>>l;
vector<pair<long, long> > oi;
priority_queue <pair<long, long>, vector<pair<long, long> >, compq> que;
for (i=0; i<n; i++)
{
in>>D>>L;
if(D <= x)
{
oi.push_back(make_pair((x-D)/l, L));
if ((x-D)/l > tm)
tm = (x-D)/l;
}
}
sort(oi.begin(), oi.end(), comp);
long j=0;
for(i=tm; i>=0; i--)
{
while(oi[j].first == i)
que.push(oi[j++]);
if(!que.empty())
{
cl+=que.top().second;
que.pop();
}
}
out<<cl;
return 0;
}