Cod sursa(job #467381)

Utilizator funkydvdIancu David Traian funkydvd Data 28 iunie 2010 16:24:41
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <stdio.h>
#include <algorithm>
#define Nmax 36
#define a first
#define b second
#define LL long long 
using namespace std;
pair<int,int> v[Nmax];
int vi[Nmax],cnt[Nmax];
int n,i,c,y,p1,j;
LL L,nr,r,S;
LL minim(LL a,LL b)
{
   return a < b ? a:b; 
}
int main()
{
	freopen("shop.in","r",stdin);
	freopen("shop.out","w",stdout);
    scanf("%d%d%lld",&n,&c,&L);
    for(i=1;i<=n;++i)
    {
		scanf("%d%d",&vi[i],&y);
        v[i]=make_pair(vi[i],y);
    }
    sort(v+1,v+n+1);
    for(i=n; i>=1 && L; i--)
    {
 		for(nr=1,j=1; j<=v[i].a && nr < L; j++) nr *= c;
        if( j == v[i].a+1 )
	    { 
			cnt[v[i].a] = minim(L/nr, v[i].b);
			S+=cnt[v[i].a];
			L-=(LL)cnt[v[i].a] * nr;
		}
	}
    printf("%lld\n",S);
    for(i=1;i<=n;++i) printf("%d ",cnt[vi[i]]);
    printf("\n");
	return 0;
}