Cod sursa(job #599722)

Utilizator SmarandaMaria Pandele Smaranda Data 29 iunie 2011 15:00:29
Problema Lupul Urias si Rau Scor 24
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
long n,x,l;
struct LUP
{
	long d,a;
};
vector <LUP> z;
queue <long> c;
inline bool cmp (LUP v , LUP w)
{
	if (v.d>w.d)
		return true;
	if (v.d<w.d)
		return false;
	if (v.d==w.d)
		if (v.a>w.a)
			return true;
		else
			return false;
}

void read ()
{
	long i;
	LUP temp;
	scanf("%ld%ld%ld",&n,&x,&l);
	for (i=1;i<=n;i++)
	{
		scanf("%ld%ld",&temp.d,&temp.a);
		z.push_back(temp);
	}
	sort(z.begin(),z.end(),cmp);
}

void rez()
{
	long i,u=0,cu;
	long long s=0,sc;
	vector <LUP> :: iterator it;
	LUP temp;
	for (it=z.begin();it!=z.end();++it)
	{
		temp=*it;
		if (temp.d+l*u<=x)  // t=(x-temp.d)/l
		{
			u++;
			c.push(temp.a);
			s=s+(long long)temp.a;
		}
		else
			if (!c.empty())
				if(temp.a>c.front())
				{
					s=(long long)s-c.back()+temp.a;
					c.pop();
					c.push(temp.a);
				}
	}
	printf("%lld\n",s);
}

int main()
{
	
	freopen("lupu.in","r",stdin);
	freopen("lupu.out","w",stdout);
	
	read();
	rez();
	return 0;
}