Pagini recente » Cod sursa (job #259015) | Cod sursa (job #990737) | Cod sursa (job #491073) | Cod sursa (job #845425) | Cod sursa (job #39495)
Cod sursa(job #39495)
# include <stdio.h>
# define _fin "shop.in"
# define _fout "shop.out"
# define maxn 33
# define myint long long
myint n, c, l, a,
v[maxn], o[maxn], b[maxn], u[maxn],
i, j, x, ttl;
inline myint pw(myint x, myint y) { return y?pw(x,y-1)*x:1; }
inline myint min(myint x, myint y) { return x<y?x:y; }
int main()
{
freopen(_fin, "r", stdin);
freopen(_fout,"w", stdout);
for (scanf("%lld%lld%lld", &n, &c, &l), i=1; i<=n; i++)
{
scanf("%d%d", &a, b+i);
v[i]=pw(c, a), o[i]=i;
}
for (i=1; i<n; i++)
for (j=i+1; j<=n; j++)
if ( v[ o[i] ] < v[ o[j] ] ) o[i]^=o[j]^=o[i]^=o[j];
for (i=1; i<=n&&l; i++)
{
ttl += (u[o[i]]=min(b[o[i]], l/v[o[i]]));
l-=(u[o[i]]*v[o[i]]);
}
for (printf("%d\n", ttl),i=1; i<n; i++) printf("%d ", u[i]);
printf("%d\n", u[i]);
return 0;
}