Cod sursa(job #248146)

Utilizator alexeiIacob Radu alexei Data 24 ianuarie 2009 23:08:34
Problema Shop Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<cstdio>
#include<algorithm>
using namespace std;

#define NMAX 32

pair< long long, int > A[NMAX];

long long SOL[NMAX];
int I[NMAX];

inline bool cmp(const int a,const int b)
{
	return A[a].first > A[b].first;
}

int main()
{
	freopen("shop.in","r",stdin);
	freopen("shop.out","w",stdout);
	
	long long N,C,ANS=0;
	long long L;
	scanf("%lld%lld%lld\n",&N,&C,&L);
	
	int i,a1,a2;
	for(i=1; i<=N; ++i)
	{
		scanf("%d%d\n",&a1,&a2);
		if( a1<=30 )
			A[i].first=1<<a1;
		else
			if( a1==31 )
				A[i].first=2147483648;
			//else
				//if( a1==32 )
				//A[i].first=4294967296;
		
		A[i].second=a2;
		I[i]=i;
	}
	
	sort( I+1, I+1+N, cmp );

	i=1;
	while( L && i<=N )
	{
		a1=I[i];

		if( A[a1].first > L || !A[a1].second )
			++i;
		else
		{
			L-=A[a1].first;
			++SOL[ a1 ];--A[a1].second;
			++ANS;
		}
	}

	printf("%lld\n",ANS);

	for(i=1; i<=N; ++i)
		printf("%lld ",SOL[i]);
	printf("\n");
	return 0;
}