Pagini recente » Cod sursa (job #549800) | Cod sursa (job #2936657) | Cod sursa (job #2382578) | Cod sursa (job #559810) | Cod sursa (job #3125860)
#include <fstream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
const int N=1e5;
int main()
{
int n,x,l;
fin>>n>>x>>l;
vector<pair<int,int>> v(n);
for(int i=0;i<n;i++)
fin>>v[i].first>>v[i].second;
sort(v.begin(),v.end(),greater<pair<int,int>>());
priority_queue<int,vector<int>,greater<int>> h;
int t_c=0;
long long l_totala=0;
for(auto p:v)
{
if(p.first + (long long)t_c * l<=x)
{
h.push(p.second);
l_totala+=p.second;
t_c++;
}
else
{
if(!h.empty() && p.second>h.top())
{
l_totala+=p.second-h.top();
h.pop();
h.push(p.second);
}
}
}
fout<<l_totala<<'\n';
return 0;
}