Pagini recente » Cod sursa (job #1436641) | Cod sursa (job #1938420) | Cod sursa (job #2432135) | Cod sursa (job #1619319) | Cod sursa (job #1599122)
#include <fstream>
#include <queue>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
typedef pair<int,int> pere;
long long sol;
priority_queue<pere> oisel,toate;
int x,l,n,dist;
void citire()
{
pere oaie;
int i;
f>>n>>x>>l;
for(i=1;i<=n;i++)
{
f>>dist>>oaie.second;
if(dist<=x)
{
oaie.first=(x-dist)/l+1;
toate.push(oaie);
}
}
}
void alegere()
{
int i,n=x/l+1;
pere oaie;
sol=0;
for(i=n;i>=1;i--)
{
while(!toate.empty() and toate.top().first>=i)
{
oaie.first=toate.top().second;
oaie.second=toate.top().first;
oisel.push(oaie);
toate.pop();
}
if(!oisel.empty())
{sol+=oisel.top().first;
oisel.pop();}
}
}
int main()
{
citire();
alegere();
g<<sol;
return 0;
}