Pagini recente » Cod sursa (job #116910) | Cod sursa (job #420496) | Cod sursa (job #60788) | Cod sursa (job #1813761) | Cod sursa (job #46611)
Cod sursa(job #46611)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct ban
{
long long c,p,u;
};
ban v[35];
int comp(const void *a, const void *b)
{
ban *aa=(ban*) a, *bb=(ban*) b;
ban x=*aa, y=*bb;
int xx=x.p,yy=y.p;
if (xx<yy)
return -1;
if (xx>yy)
return 1;
return 0;
}
int main()
{
long long i,c,l,n,cused=0,max,x,y,z=0;
FILE *in=fopen("shop.in","r"),*out=fopen("shop.out","w");
fscanf(in,"%lld%lld%lld",&n,&c,&l);
for (i = 0 ; i < n; i++)
fscanf(in,"%lld%lld",&v[i].p,&v[i].c);
fclose(in);
while (l && cused<=n)
{
max=n;
for (i=0; i<n; i++)
if (v[i].p>=v[max].p && v[i].c!=0)
max=i;
x=(long long)pow(c,v[max].p);
y=l/x;
if (v[max].c<y)
y=v[max].c;
z+=y;
v[max].u=y;
l-=x*y;
v[max].c=0;
cused++;
}
fprintf(out,"%lld\n",z);
for (i=0; i<n-1; i++)
fprintf(out,"%lld ",v[i].u);
fprintf(out,"%lld\n",v[n-1].u);
fclose(out);
return 0;
}