Pagini recente » Cod sursa (job #36764) | Cod sursa (job #2056711) | Cod sursa (job #1271520) | Cod sursa (job #2212124) | Cod sursa (job #46779)
Cod sursa(job #46779)
#include<stdio.h>
long long n,c,a[31],b[31],i,j,l,scad,m,k,aux,h[31],v[31],sum;
long long putere(long long p)
{
long long put=1;
for (long long i=1;i<=p;i++)
put*=c;
return put;
}
int main()
{
freopen ("shop.in","rt",stdin);
freopen ("shop.out","wt",stdout);
scanf("%lld %lld %lld",&n,&c,&l);
for (i=1;i<=n;i++)
scanf("%lld %lld",&a[i],&b[i]),h[i]=i;
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
{
if (a[i]<a[j])
{
aux=a[i],a[i]=a[j],a[j]=aux;
aux=b[i],b[i]=b[j],b[j]=aux;
aux=h[i],h[i]=h[j],h[j]=aux;
}
}
i=1;
while (l)
{
k=putere(a[i]);
m=l/k;
scad=b[i]<m?b[i]:m;
l-=scad*k;
v[h[i]]+=scad;
sum+=scad;
i++;
}
printf("%lld\n",sum);
for (i=1;i<=n;i++)
printf("%lld ",v[i]);
printf("\n");
return 0;
}